我想在应用程序定义后动态添加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();}} })
}]);
我该怎么做呢?此处的关键是在定义/配置后添加。因此,此代码将在将来的某个时候运行。
最佳答案
它是
app.run(function ($route) {
var route = $route.routes['/...'];
route.resolve = route.resolve || {};
route.resolve.someResolver = ...;
});
关于javascript - Angular $ routeProvider-以编程方式添加路线解析,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33508001/