Angular error: [$injector:unpr] Unknown provider: lineChartProvider <- lineChart <- MainController
Angular error: [$injector:unpr] Unknown provider: lineChartProvider <- lineChart <- MainController
不知道为什么,但我的控制器无法识别该服务。我已经检查了我在这里遗漏了什么。我已将服务文件包含在 HTML 中。它识别其他服务,但不只是这个
(function() {
'use strict';
angular
.module('pollyvotes')
.service('lineChart', lineChart);
/** @ngInject */
function lineChart($scope, $http){
var promise = null;
return function(){
if (promise){
return promise
} else {
promise = $http.jsonp('')
.success(function(data){
$scope.predictions = data;
})
.error( function(data){
$scope.data = "Request failed";
})
return promise;
}
}
控制器
(function() {
'use strict';
angular
.module('pollyvotes')
.controller('MainController', MainController);
/** @ngInject */
function MainController($scope, $timeout, lineChart) {
$scope.photos = [ {id: 'chart-1', name: 'something here',src: "assets/images/300x600.png", href: "https://www.google.de/?gws_rd=ssl", discription: "say something about the chart here"},
{id: 'chart-2', name: 'another picture', src: "assets/images/300x600.png", href: "https://www.google.de/?gws_rd=ssl", discription: "say something about the chart here"},
{id: 'chart-3', name: 'another picture', src: "assets/images/300x600.png", href: "https://www.google.de/?gws_rd=ssl", discription: "say something about the chart here"},
{id: 'chart-4', name: 'another picture', src: "assets/images/300x600.png", href: "https://www.google.de/?gws_rd=ssl", discription: "say something about the chart here"}
];
}
})();
并声明模块
(function() {
'use strict';
angular
.module('pollyvotes', ['ngAnimate', 'ngCookies', 'ngTouch', 'ngSanitize',
'ngMessages', 'ngAria', 'ngResource', 'ui.router',
'ui.bootstrap', 'akoenig.deckgrid', 'smoothScroll',
'ngToast', 'picardy.fontawesome']);
})();
您正在向您的服务注入 $scope。
文档中是这样描述这个错误的:
https://docs.angularjs.org/error/$injector/unpr
Attempting to inject a scope object into anything that's not a controller or
a directive, for example a service, will also throw an
Unknown provider: $scopeProvider <- $scope error.
这里有一个关于如何避免这种情况的很好的答案:
Injecting $scope into an angular service function()
不知道为什么,但我的控制器无法识别该服务。我已经检查了我在这里遗漏了什么。我已将服务文件包含在 HTML 中。它识别其他服务,但不只是这个
(function() {
'use strict';
angular
.module('pollyvotes')
.service('lineChart', lineChart);
/** @ngInject */
function lineChart($scope, $http){
var promise = null;
return function(){
if (promise){
return promise
} else {
promise = $http.jsonp('')
.success(function(data){
$scope.predictions = data;
})
.error( function(data){
$scope.data = "Request failed";
})
return promise;
}
}
控制器
(function() {
'use strict';
angular
.module('pollyvotes')
.controller('MainController', MainController);
/** @ngInject */
function MainController($scope, $timeout, lineChart) {
$scope.photos = [ {id: 'chart-1', name: 'something here',src: "assets/images/300x600.png", href: "https://www.google.de/?gws_rd=ssl", discription: "say something about the chart here"},
{id: 'chart-2', name: 'another picture', src: "assets/images/300x600.png", href: "https://www.google.de/?gws_rd=ssl", discription: "say something about the chart here"},
{id: 'chart-3', name: 'another picture', src: "assets/images/300x600.png", href: "https://www.google.de/?gws_rd=ssl", discription: "say something about the chart here"},
{id: 'chart-4', name: 'another picture', src: "assets/images/300x600.png", href: "https://www.google.de/?gws_rd=ssl", discription: "say something about the chart here"}
];
}
})();
并声明模块
(function() {
'use strict';
angular
.module('pollyvotes', ['ngAnimate', 'ngCookies', 'ngTouch', 'ngSanitize',
'ngMessages', 'ngAria', 'ngResource', 'ui.router',
'ui.bootstrap', 'akoenig.deckgrid', 'smoothScroll',
'ngToast', 'picardy.fontawesome']);
})();
您正在向您的服务注入 $scope。
文档中是这样描述这个错误的: https://docs.angularjs.org/error/$injector/unpr
Attempting to inject a scope object into anything that's not a controller or a directive, for example a service, will also throw an Unknown provider: $scopeProvider <- $scope error.
这里有一个关于如何避免这种情况的很好的答案: Injecting $scope into an angular service function()