Angular JS - Make service globally accessible from controllers and view

前端 未结 3 698
青春惊慌失措
青春惊慌失措 2020-12-02 11:39

Let\'s say we have the following service:

myApp.factory(\'FooService\', function () { ...

Then, from a controller, I would say:

         


        
3条回答
  •  感情败类
    2020-12-02 11:59

    Complementing question #1 (Global accesibillity) I will only add that in order to avoid issues when minifiying the file (if that's the case) it should be written like this:

    this.app.run(["$rootScope", "Foo", function($rootScope, FooService) {
        return $rootScope.fooService = FooService;
      }
    ]);
    

提交回复
热议问题