有几个问题浮出同样的错误,常见的分辨率是angular.js版本与angular-route.js不同步。
我认为这不是我的情况。
我正在尝试运行其他人编写的演示应用程序。我收到的这个错误并没有给我留下任何关于出错的线索。
Error: [$injector:unpr] Unknown provider: $templateRequestProvider <- $templateRequest <- $route <- ngViewDirective
http://errors.angularjs.org/1.2.28/$injector/unpr?p0=%24templateRequestProvider%20%3C-%20%24templateRequest%20%3C-%20%24route%20%3C-%20ngViewDirective
at angular.js:78
at angular.js:3801
at Object.getService [as get] (angular.js:3929)
at angular.js:3806
at getService (angular.js:3929)
at Object.invoke (angular.js:3956)
at angular.js:3807
at getService (angular.js:3929)
at Object.invoke (angular.js:3956)
at angular.js:5716
我可以做些什么来调试这个?
源代码在这里:https://github.com/DataTorrent/malhar-dashboard-webapp
基本上,路由和控制器的设置如下:
'use strict';
angular.module('app', [
'ngRoute',
'ui.dashboard',
'btford.markdown'
])
.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'template/view.html',
controller: 'DemoCtrl',
title: 'simple',
description: 'This is the simplest demo.'
})
.when('/resize', {
templateUrl: 'template/view.html',
controller: 'ResizeDemoCtrl',
title: 'resize',
description: 'This demo showcases widget resizing.'
})
.when('/custom-settings', {
templateUrl: 'template/view.html',
controller: 'CustomSettingsDemoCtrl',
title: 'custom widget settings',
description: 'This demo showcases overriding the widget settings dialog/modal ' +
'for the entire dashboard and for a specific widget. Click on the cog of each ' +
'widget to see the custom modal. \n"configurable widget" has "limit" option in the modal ' +
'that controls RandomDataModel.'
})
.when('/explicit-saving', {
templateUrl: 'template/view.html',
controller: 'ExplicitSaveDemoCtrl',
title: 'explicit saving',
description: 'This demo showcases an option to only save the dashboard state '+
'explicitly, e.g. by user input. Notice the "all saved" button in the controls ' +
'updates as you make saveable changes.'
})
.when('/layouts', {
templateUrl: 'template/layouts.html',
controller: 'LayoutsDemoCtrl',
title: 'dashboard layouts',
description: 'This demo showcases the ability to have "dashboard layouts", ' +
'meaning the ability to have multiple arbitrary configurations of widgets. For more ' +
'information, take a look at [issue #31](https://github.com/DataTorrent/malhar-angular-dashboard/issues/31)'
})
.when('/layouts/explicit-saving', {
templateUrl: 'template/layouts.html',
controller: 'LayoutsDemoExplicitSaveCtrl',
title: 'layouts explicit saving',
description: 'This demo showcases dashboard layouts with explicit saving enabled.'
})
.otherwise({
redirectTo: '/'
});
})
.controller('NavBarCtrl', function($scope, $route) {
$scope.$route = $route;
})
.factory('widgetDefinitions', function(RandomDataModel) {
return [
{
name: 'random',
directive: 'wt-scope-watch',
attrs: {
value: 'randomValue'
}
},
{
name: 'time',
directive: 'wt-time'
},
{
name: 'datamodel',
directive: 'wt-scope-watch',
dataAttrName: 'value',
dataModelType: RandomDataModel
},
{
name: 'resizable',
templateUrl: 'template/resizable.html',
attrs: {
class: 'demo-widget-resizable'
}
},
{
name: 'fluid',
directive: 'wt-fluid',
size: {
width: '50%',
height: '250px'
}
}
];
})
.value('defaultWidgets', [
{ name: 'random' },
{ name: 'time' },
{ name: 'datamodel' },
{
name: 'random',
style: {
width: '50%'
}
},
{
name: 'time',
style: {
width: '50%'
}
}
])
.controller('DemoCtrl', function ($scope, $interval, $window, widgetDefinitions, defaultWidgets) {
$scope.dashboardOptions = {
widgetButtons: true,
widgetDefinitions: widgetDefinitions,
defaultWidgets: defaultWidgets,
storage: $window.localStorage,
storageId: 'demo_simple'
};
$scope.randomValue = Math.random();
$interval(function () {
$scope.randomValue = Math.random();
}, 500);
});
使用intellij调试器,我将其缩小了一点。它发生在module.config完成之后,但在调用DemoCtrl之前。
更新3: 它似乎在angular.js中的这个函数内崩溃:
this.directive = function registerDirective(name, directiveFactory) {
当名称是&#34; ngView&#34;。