不确定为什么,但我的控制器不会识别该服务。我检查了一下我在这里缺少的东西。我已将服务文件包含在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']);
})();
答案 0 :(得分:1)
您正在为您的服务注入$ scope。
这就是文档中关于此错误的说法: https://docs.angularjs.org/error/ $注射器/ unpr
尝试将范围对象注入任何非控制器或 一个指令,例如一个服务,也将抛出一个 未知提供者:$ scopeProvider< - $ scope error。
这里有一个很好的答案如何避免这种情况: Injecting $scope into an angular service function()