Behavior of controller inside directives

前端 未结 3 2103
花落未央
花落未央 2020-12-14 09:00

I know that a $scope from a controller can be shared to a link function in directives.

For example, in this code I can call a

3条回答
  •  佛祖请我去吃肉
    2020-12-14 09:41

    See updated plunker: http://plnkr.co/edit/pT8rEDz7gWKUPYIZhUYA?p=preview

    1. Yes, this is the same scope. The id's are the same, and you can see that the contents were updated.
    2. The implications of a shared scope is that it's hard to track down who changed what. I would highly recommend that your directives use an isolate scope.
    3. Feel free to manipulate the DOM. Tracking down changes will be a fun exercise... I would also highly recommend against any DOM manipulation. I would segregate DOM manipulation from other activities by wrapping them up in a directive.

    One of Angular's strong points is directives, so I would use them wherever possible to separate your concerns.

提交回复
热议问题