AngularJS - Dependency injection in services, factories, filters etc

前端 未结 3 1936
孤城傲影
孤城傲影 2021-01-30 02:08

So I have some plugins and libraries I want to use in my angular app and (currently) I am simply referencing those functions/methods as they were intended in 99% of apps in a wa

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-30 02:49

    Yes you can use dependency injection for filters and directives

    Ex:

    Filter:

    app.filter('', ['$http', function(http){
        return function(data){
        }
    }]);
    

    Directive:

    app.directive('', ['$http', function(http){
        return {
            ....
        }
    }]);
    

    Service:

    app.factory('', ['$http', function(http) {
      var shinyNewServiceInstance;
      return shinyNewServiceInstance;
    }]);
    

提交回复
热议问题