I'd like to add Angular resolve
dynamically after it was defined by the app. Imagine, my app is defined with routes like this:
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when("/", {templateUrl: "partials/home.html", controller: "PageCtrl" })
.when("/services", {templateUrl: "partials/services.html", controller: "PageCtrl" })
}]);
Then later I want to add/edit/override specific route(s) to resolve
a promise:
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when("/services", {templateUrl: "partials/services.html", controller: "PageCtrl", ,resolve:{getData: function(myService){return myService.getOffer();}} })
}]);
How do I do this? The key here is adding after it was defined/configured. So this code will run at some point in the future.
It is
app.run(function ($route) {
var route = $route.routes['/...'];
route.resolve = route.resolve || {};
route.resolve.someResolver = ...;
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.