$ injector:unpr未知的提供程序->找不到失败的原因

时间:2019-11-19 10:24:29

标签: angularjs

我遇到以下错误:

  

angular.js:14199错误:[$ injector:unpr]未知提供程序:ComplianceServiceProvider <-ComplianceService <-ComplianceController

在以下Controller中:

(function () {
    angular.module('tasksModule')
     .controller('ComplianceController', ComplianceController)

     function ComplianceController($log, configService, scheduleService, dateTimeService, storeService,
            areaService, complianceService) {

      ..... some code here

    }
})();

以及以下Service

(function(){
   angular.module('tasksModule')
    .service('complianceService', ComplianceService)

   function ComplianceService($log, $tasksApi) {
      var vm = this

      vm.get = get

      function get(filter){
        $log.debug('Service - ComplianceService - get')

        return $tasksApi
           .then(function(v){
              return v.$request().$get('compliance', filter)
           })
          .then(Compliance)
      }

      function Compliance(resource) {
        return {
          resource : resource,
          tasks : resource.tasks
        }
      }
   }   
})

但是我遇到了injector错误,为什么?有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

调用功能:

(function(){
   angular.module('tasksModule')
    .service('complianceService', ComplianceService)

   function ComplianceService($log, $tasksApi) {
      var vm = this

      vm.get = get

      function get(filter){
        $log.debug('Service - ComplianceService - get')

        return $tasksApi
           .then(function(v){
              return v.$request().$get('compliance', filter)
           })
          .then(Compliance)
      }

      function Compliance(resource) {
        return {
          resource : resource,
          tasks : resource.tasks
        }
      }
   }   
̶}̶)̶
//IMPORTANT - Invoke the function
})()

调用该函数很重要。

有关更多信息,请参见