This is my route:
$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;
}
}
});
this is my controller:
app.controllers.controller('blogEditPostController', function(loadData) {
});
and this is the blog service:
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);
});
}
};
});
The defer.resolve function gets called, my template gets loaded and the content of the result variable is correct; but I get this error:
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
When I try to load the view again after getting the error above I get this error:
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)
What am I missing here? I've used the same syntax before and it worked just fine
Turns out that I've included the controller twice. In the route and also in the HTML Template. I've removed it from the HTML template now and everything works!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With