AngularJS, is this way of using service good?

后端 未结 3 1795
误落风尘
误落风尘 2020-12-13 01:05

i\'ve this HTML:

Hello {{name}}

and the controller is:

function myCtrl(scope, service) {
    scope.name          


        
3条回答
  •  伪装坚强ぢ
    2020-12-13 01:23

    Another way to do it:

    Expose the service on $rootScope:

    $rootScope.service = service;
    

    and then in a template:

    Hello {{service.getUsername();}}

    You can do this on app.run, and you will get the service in all the views of your app. You could use this method for Authentication services.

提交回复
热议问题