Route Resolving + Multiple Controller Combo?
I'm trying to combine 2 concepts and I'm having trouble making them work together. Concept 1: Route resolving. This is easy to explain, I just want to resolve certain models like t
Solution 1:
It's hard to help you when we don't know what the "base controller"'s responsibilities are. For me, the Concept 3 you are looking for is as follows:
$routeProvider
.when("/news", {
templateUrl: "news.html",
controller: "newsCtrl",
resolve: { news: function(Model) { return Model.news.getList(); })
.when("/news/latest", {
templateUrl: "news.html",
controller: "newsLatestCtrl"},
resolve: { newsLatest: function(Model) { return Model.news.getLatest(); });
module.controller('newsCtrl', function($scope, news) {
/* common code you want to share */
});
module.controller('newsLatestCtrl', function($scope, newsLatest, $controller) {
// instantiate your "base controller"
var ctrl = $controller('newsCtrl', {
"$scope": $scope,
"news": newsLatest
});
// customize and add special code for latest news
});
Post a Comment for "Route Resolving + Multiple Controller Combo?"