我想在应用程序定义后动态添加Angular resolve
。想象一下,我的应用程序定义了这样的路线:
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when("/", {templateUrl: "partials/home.html", controller: "PageCtrl" })
.when("/services", {templateUrl: "partials/services.html", controller: "PageCtrl" })
}]);
然后我想添加/编辑/覆盖特定路线到resolve
承诺:
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when("/services", {templateUrl: "partials/services.html", controller: "PageCtrl", ,resolve:{getData: function(myService){return myService.getOffer();}} })
}]);
我该怎么做?这里的关键是在定义/配置后添加。所以这段代码将在未来某个时候运行。
答案 0 :(得分:1)
是
app.run(function ($route) {
var route = $route.routes['/...'];
route.resolve = route.resolve || {};
route.resolve.someResolver = ...;
});