我试图在angularJs中实现定制指令的双向绑定。不知怎么不起作用了。
html文件
<div ng-app='myApp'>Outside directive
<input type='text' ng-model='outAttr'>{{outAttr}}</br>
<div my-directive some-attr='outAttr'></div>
</div>js文件
var myApp = angular.module('myApp', []);
myApp.directive('myDirective', function () {
return {
restrict: 'A,
replace: true,
scope: {
inAttr: '=someAttr';
},
template: "<div><input type='text' ng-model='inAttr'>\
{{inAttr}}</div>"
}
})不知怎么不起作用了。这是JSFiddle链路。有人能帮我指出我的错误吗。谢谢。
发布于 2014-08-28 18:34:26
语法错误很少。代码的逻辑是OK - jsFiddle。
var myApp = angular.module('myApp', []);
myApp.directive('myDirective', function() {
return {
restrict: 'A', // missing '
replace: true,
scope: {
inAttr: '=someAttr' // no ;
},
template: '<div><input type="text" ng-model="inAttr">{{inAttr}}</div>' // no break
};
});https://stackoverflow.com/questions/25553839
复制相似问题