angularjs – 在嵌套指令中传递ng-model
发布时间:2020-12-17 08:37:20 所属栏目:安全 来源:网络整理
导读:我想把我的ng模型从’outer-directive’传递到’inner-diretive'(包含在outer-directive模板中)。 什么是正确的方式做呢? HTML代码: body outer-directive ng-model="prop" //body 和指令代码: angular.module('app',[]).directive('outerDirective',func
我想把我的ng模型从’outer-directive’传递到’inner-diretive'(包含在outer-directive模板中)。
什么是正确的方式做呢? HTML代码: <body> <outer-directive ng-model="prop" /> </body> 和指令代码: angular.module('app',[]).directive('outerDirective',function(){ return { template: '<inner-directive ng-model="prop" />',link: function() { ... } } });
您可以使用ngModel属性中的变量设置双向绑定(请参阅
documentation,“指令定义对象”一节),与其他任何指令一样:
<my-directive ng-model="foo"></my-directive> myApp.directive('myDirective',function () { return { template: '<div><input type="text" ng-model="ngModel" /></div>',replace: true,scope: { ngModel : '=',},}; }); Fiddle (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |