Angularjs: inject required directive-controller into the controller instead of the link function

后端 未结 3 745
挽巷
挽巷 2020-12-15 22:33

Normal use cases in angular

If you have a parent directive and a child directive you create methods in the controller of the parent directive and re

3条回答
  •  半阙折子戏
    2020-12-15 23:13

    Actually there is another way that is less verbose and is used by the angular ngModel itself:

    var parentForm = $element.inheritedData('$formController') || ....
    

    Basically they use the fact that the controllers are stored into the data property of the directive dom element.

    Still a bit wired, but less verbose and easier to understand.

    I don't see a reason why you cannot pass the required controllers into the injection locals for the directive controller.

提交回复
热议问题