Directive isolate scope with ng-repeat scope in AngularJS

前端 未结 2 1489
青春惊慌失措
青春惊慌失措 2020-11-27 09:20

I have a directive with an isolate-scope (so that I can reuse the directive in other places), and when I use this directive with an ng-repeat, it fails to work.

2条回答
  •  有刺的猬
    2020-11-27 09:40

    Without directly trying to avoid answering your questions, instead take a look at the following fiddle:

    http://jsfiddle.net/dVPLM/

    Key point is that instead of trying to fight and change the conventional behaviour of Angular, you could structure your directive to work with ng-repeat as opposed to trying to override it.

    In your template:

        
        
    

    In your directive:

        template:
    '        '
    

    In response to your questions:

    • ng-repeat will create a scope, you really shouldn't be trying to change this.
    • Priority in directives isn't just execution order - see: AngularJS : How does the HTML compiler arrange the order for compiling?
    • In Batarang, if you check the performance tab, you can see the expressions bound for each scope, and check if this matches your expectations.

提交回复
热议问题