【发布时间】:2016-05-07 08:44:12
【问题描述】:
我正在尝试访问位于指令模板中的模型。但是指令的范围从不显示该模型。我做错了什么?
http://jsbin.com/xorujuqube/edit?html,js,console,output [JSBIN-参考]
【问题讨论】:
标签: angularjs scope directive angular-ngmodel
我正在尝试访问位于指令模板中的模型。但是指令的范围从不显示该模型。我做错了什么?
http://jsbin.com/xorujuqube/edit?html,js,console,output [JSBIN-参考]
【问题讨论】:
标签: angularjs scope directive angular-ngmodel
http://jsbin.com/facotegene/1/edit?html,js,console,output
有几件事,当您从父级传递一个变量时,您只需使用of: "="(这将在父级和指令之间创建一个双向绑定)。其次,<test-d of="'test'"></test-d> 需要一个角度变量($scope 或 var 附加到 Ctrl)。因此,如果您只想用字符串测试它,则必须使用这样的引号。
【讨论】:
template: <div ng-model=h>test</div> 更改为<div ng-model=of>test</div>,因为这是您的scope var 的名称
是的,我缺少的是,从指令以及对象和属性变量即初始化模型。 $scope.Obj.proper = true ;
【讨论】: