【发布时间】:2016-02-18 16:16:05
【问题描述】:
我正在尝试利用adds the resolve map to the scope of the route 的(1.5.0 中的新功能)功能。但是,似乎直到控制器加载后地图才真正添加到范围中。
这是一个演示问题的非常简单的模块(来自plunk):
var app = angular.module("app", ['ngRoute']);
app.config(['$routeProvider', '$locationProvider',
function($routeProvider, $locationProvider) {
$routeProvider.otherwise({
controller: "editController",
controllerAs: "ec",
templateUrl: "edit.html",
resolve: {
resolveData: function() {
return {
foo: "bar",
blah: "halb"
}
}
}
});
}
]);
app.controller("editController", ["$scope", function($scope) {
// undefined
console.log($scope.$resolve);
setTimeout(function() {
// the object is there, including $scope.$resolve.resolveData
console.log($scope.$resolve);
}, 0)
}]);
如果您查看控制台,您会注意到创建控制器时$scope.$resolve 是undefined。但是,它会在之后立即出现,正如 setTimeout 所展示的那样。
我在文档中找不到任何表明应该是这种情况的内容。这是一个错误吗?还是我只是没有了解 Angular 的工作原理?
【问题讨论】:
标签: javascript angularjs angularjs-scope angularjs-routing