AngularJs。未知提供商 - routeParams

时间:2016-09-19 07:15:42

标签: angularjs angular-routing

我曾经多次使用类似的代码,但从来没有任何错误,但现在,当我需要读取url参数时,出现了问题。
以下是应用程序配置的一部分:

angular.module('NitkaApp', [
    'ngMaterial',
    'ngMessages',
    'ngRoute',
    'ngResource',
    'ngSanitize',
    'books',
    'details',
    'authors',
    'images',
    'dataService'
]).
    config([
        "$locationProvider", "$routeProvider", "$mdThemingProvider", function ($locationProvider, $routeProvider, $mdThemingProvider) {
            $locationProvider.html5Mode({
                enabled: true
            });
            $mdThemingProvider.theme('default')
                .primaryPalette('blue-grey')
                .accentPalette('brown');
            $routeProvider
                .when('/', {
                    templateUrl: '/app/html/books.html',
                    controller: 'BooksCtrl'
                })
                .when('/book/:id', {
                    templateUrl: '/app/html/book-details.html',
                    controller: 'BookDetailsCtrl'
                })

这是控制器的一部分:

(function () {
    "use strict";
    angular.module('details', []).controller("BookDetailsCtrl", ["$scope", "$location", "$rootParams", "$mdMedia", "NitkaService", function ($scope, $location, $rootParams, $mdMedia, NitkaService) {
        //Getting external data from service
        NitkaService.getBook($rootParams.id).then(function(d) {
            $scope.bookDetails = d.data;
        });

当然我有角度路线库链接。你能建议解决这个问题吗?附:当然,我在SO上阅读了所有类似的帖子。

1 个答案:

答案 0 :(得分:3)

在控制器的依赖项中,它应该是routeParams,更改

发件人

angular.module('details', []).controller("BookDetailsCtrl", ["$scope", "$location", "$rootParams", "$mdMedia", "NitkaService", function ($scope, $location, $rootParams, $mdMedia, NitkaService) {
        //Getting external data from service
        NitkaService.getBook($rootParams.id).then(function(d) {
            $scope.bookDetails = d.data;
        });

 angular.module('details', []).controller("BookDetailsCtrl", ["$scope", "$location", "$routeParams", "$mdMedia", "NitkaService", function ($scope, $location, $routeParams, $mdMedia, NitkaService) {
        //Getting external data from service
        NitkaService.getBook($routeParams.id).then(function(d) {
            $scope.bookDetails = d.data;
        });