Angularjs ng-controller with resolve

前端 未结 8 677
时光取名叫无心
时光取名叫无心 2021-02-01 20:30

I\'ve ran into problem with ng-controller and \'resolve\' functionality:

I have a controller that requires some dependency to be resolved before running, it works fine w

8条回答
  •  误落风尘
    2021-02-01 21:14

    Create a new module inside which you have the service to inject like seen below.

    var module = angular.module('myservice', []);
    
    module.service('userService', function(Service){
        return Service.getData();
    });
    

    Inject newly created service module inside your app module

    angular.module('myApp')
      .controller('MyController', ['$scope', 'myservice', function ($scope, myservice) {
          $scope.data = data;
        // now you can use new dependent service anywhere here.
        }
      ]
    );
    

提交回复
热议问题