指令绑定未定义
Directive binding undefined
我对angularjs有点陌生。我正在编写一个指令,但我无法理解 bindToController 是如何运行的。我 http://blog.thoughtram.io/angularjs/2015/01/02/exploring-angular-1.3-bindToController.html 阅读了这篇有用的文章,但我不明白为什么在下面的示例中我未定义。
.directive('firstDirective', function(){
return {
restrict: 'E',
replace: true,
scope: true,
bindToController: {
directiveInput:'='
},
templateUrl: 'components/directive-tree/directive-tree.html',
controllerAs: 'directiveTreeCtrl',
controller: function($scope, $uibModal){
var self = this;
self.selected = null;
console.log(self.directiveInput); //HERE IS THE UNDEFINED
$scope.modalOptions = {
windowClass: 'semi-modal',
}
this.openDirectiveModal = function(object, index) {
//Other irrelevant code
}
}
}
});
之后,我可以毫无问题地使用 HTML 模板的输入。
<ul>
<li ng-repeat="object in directiveTreeCtrl.directiveInput">
{{object.Id}} {{object.Name}}
</li>
</ul>
为什么我可以在 HTML 模板中使用 directiveInput 并且它使用正确的值和我的控制台实例化.log显示"未定义"?
也许这是一个愚蠢的问题。谢谢
通常,我为此编写的代码如下所示:
.directive('firstDirective', function(){
return {
restrict: 'E',
replace: true,
scope: {
directiveInput:'='
},
bindToController: true,
templateUrl: 'components/directive-tree/directive-tree.html',
controllerAs: 'directiveTreeCtrl',
controller: function($scope, $uibModal){
var self = this;
self.selected = null;
console.log(self.directiveInput); //HERE IS THE UNDEFINED
$scope.modalOptions = {
windowClass: 'semi-modal',
}
this.openDirectiveModal = function(object, index) {
//Other irrelevant code
}
}
}
});
现在的 HTML
<first-directive directive-input="inputObject"></first-directive>
相关文章:
- AngularJS 1.5.x服务未正确绑定,并且未在控制器中更新
- 使用Knockout自定义绑定更新JSTree
- 提高敲除自定义绑定的效率(经常开火)
- 安卓键盘未打开绑定到触摸启动的输入标签
- Knockout自定义绑定不会't更新
- 正在将逻辑从视图移动到自定义绑定
- 取消计算列的自定义绑定
- 如何使用segment.io's analystics.js在一个敲除自定义绑定中
- 更改可观察数组会更改自定义绑定处理程序knockoutjs的可见性
- Angular$watch未更新绑定
- 去掉foreach中的自定义绑定以获取迭代器
- 从敲除js自定义绑定中获取foreach的值
- KnockoutJS:将if绑定封装在自定义绑定中
- 更改自定义绑定处理程序,以便使用IIFE进行分配
- Knockout Js的自定义绑定处理程序更新依赖项
- d3.js enter()未正确绑定到数据-正在重新创建现有数据
- 自定义绑定在KnockoutJS 3.0中不再工作
- Knockout:在创建自定义绑定后,绑定未应用于页面的一部分
- 淘汰自定义绑定处理程序:$root未定义
- 如何为Hogan.js创建自定义绑定语法(未转义的HTML版本)