use*_*782 36 angularjs angularjs-directive
我想将我的ng-model从'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() { ... }
    }
});
Bla*_*ole 44
您可以使用属性中的变量设置双向绑定(请参阅文档 "指令定义对象"部分)ngModel,与任何其他指令一样:
<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 : '=',
        },
    };
});
| 归档时间: | 
 | 
| 查看次数: | 22507 次 | 
| 最近记录: |