Injecting services into AngularJS directive controller directly

后端 未结 2 1526
傲寒
傲寒 2021-02-19 07:44

I understand how Angular dependency injection works with directives but wanted clarification on something. I have a dummy test directive as follows:

app.directiv         


        
2条回答
  •  暖寄归人
    2021-02-19 08:21

    In this case, you're receiving the same service, so it likely doesn't matter too much. I personally prefer to keep them as localized as possible; if you don't need $filter in the link function or something like that, I'd just inject it into the controller.

    In certain cases, this may also make it easier to mock dependencies during testing.

提交回复
热议问题