我正在使用 Angular 1.5.7 版本。
我有一个指令,它将 Controller 名称和 View 名称作为字符串来分别调用 Controller 。
我无法将用户名绑定(bind)到前一个 Controller 的调用 Controller ,我看到了前一个 Controller 中可用的值。
请你能告诉我可能是什么问题吗?
myApp.directive("pendingRequests", function() {
return {
restrict: 'E',
controller: "@",
name: "controllerName",
controllerAs: 'pendingReqCtrl',
scope: {},
bindToController: {
username: '=username'
},
templateUrl: function(tElement, tAttrs) {
return tAttrs.templateUrl;
}
};
});
最佳答案
您是否尝试过 $onInit 来初始化您的代码?
angularjs doc says this :
Deprecation warning: although bindings for non-ES6 class controllers are currently bound to this before the controller constructor is called, this use is now deprecated. Please place initialization code that relies upon bindings inside a $onInit method on the controller, instead.
我更新到 1.6.2,我不得不将我的代码放入 $onInit 方法来访问绑定(bind)。
关于angularjs - Angular bindToController 不起作用,可以将对象从一个 Controller 范围绑定(bind)到另一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42256762/