gpt4 book ai didi

angularjs - 无法将解析数据注入(inject)我的 Controller

转载 作者:行者123 更新时间:2023-12-04 05:52:43 25 4
gpt4 key购买 nike

这是我的路线:

$routeProvider.when('/blog/bearbeiten/:id', {
templateUrl: 'adminpages/blog/beitragbearbeiten',
controller: 'blogEditPostController',
resolve: {
loadData: function($q, $route, blog) {
var defer = $q.defer();
var post = $route.current.params.id;

var fn = function(result) {
defer.resolve(result);
};
blog.getPost(post, fn);
return defer.promise;
}
}
});

这是我的 Controller :
app.controllers.controller('blogEditPostController', function(loadData) {

});

这是博客服务:
app.services.factory('blog', function ($http) {
return {
getPosts: function(page, fn) {
$http.get('/api/posts/' + page).
success(function(data) {
fn(data);
});
},
getPost: function(id, fn) {
$http.get('/api/post/' + id).
success(function(data) {
console.log(data);
fn(data);
});
}
};
});

defer.resolve 函数被调用,我的模板被加载并且结果变量的内容是正确的;但我收到此错误:

Error: Unknown provider: loadDataProvider <- loadData at Error () at http://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js:2765:19 at Object.getService [as get] (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js:2891:39) at http://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js:2770:45 at getService (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js:2891:39) at invoke (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js:2909:13) at Object.instantiate (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js:2943:23) at http://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js:5368:28 at http://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js:4937:17 at forEach (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js:155:20) angular.js:6349



当我在收到上述错误后再次尝试加载 View 时,我收到此错误:

Error: Circular dependency: at Error () at getService (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js:2884:17) at invoke (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js:2909:13) at Object.instantiate (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js:2943:23) at http://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js:5368:28 at http://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js:4937:17 at forEach (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js:155:20) at nodeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js:4922:11) at compositeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js:4550:15) at compositeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js:4553:13)



我在这里想念什么?我以前使用过相同的语法,它工作得很好

最佳答案

原来我已经包含了两次 Controller 。在路线和 HTML 模板中。我现在已经从 HTML 模板中删除了它,一切正常!

关于angularjs - 无法将解析数据注入(inject)我的 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17307339/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com