簡體   English   中英

出現“錯誤:[$ injector:unpr]未知提供程序”錯誤

[英]Getting “Error: [$injector:unpr] Unknown provider” error

我正在基於此實踐編寫路由解析: https : //github.com/johnpapa/angular-styleguide#style-y081

但我得到:

錯誤:[$ injector:unpr]未知提供程序:toursServiceProvider <-toursService <-MainController

我的代碼如下:route-config.js文件

.when('/', {
    templateUrl: 'scripts/partials/home.partial.html',
    controller: 'MainController',
    controllerAs: 'vm',
    resolve: {
        toursService: function(genericData) {
            return genericData.getTours;
        },
        addressService: function(genericData) {
            return genericData.getAddress;
        },
        aboutService: function(genericData) {
            return genericData.getAbout;
        }
    }

})

main.controller.js文件:

(function () {

    'use strict';

    angular
        .module('excursion')
        .controller('MainController', MainController);

    MainController.$inject = ['toursService', 'addressService', 'aboutService'];

    function MainController(toursService, addressService, aboutService) {

        // vm is our capture variable
        var vm = this;

        vm.tour = toursService.getTours;
        vm.address = addressService.getAddress;
        vm.about = aboutService.getAbout;

    }
})();

終於我開始工作了,我需要$ timeout使承諾在加載控制器時可用,這是更新的代碼(只是路由不同,但邏輯是相同的):

.when('/tours', {
    templateUrl: 'scripts/partials/pages/tours.partial.html',
    controller: 'TourController',
    controllerAs: 'vm',
    resolve: {
        toursService: function(genericData, $timeout) {
            return $timeout(function() {
                return genericData.getTours;
            }, 1000);
        }
    }
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM