【发布时间】:2014-07-22 02:45:08
【问题描述】:
我正在尝试使用角度指令中的模型更新我的视图,这是我创建的指令
app.directive('aboutOptions', [function() {
return {
restrict: 'C',
scope: {
testing: '='
},
transclude: true,
link: function(scope, elem, attr) {
scope.$watch(attr.ngModel, function() {
console.log(scope.$eval(attr.ngModel));
scope.testing = scope.$eval(attr.ngModel);
});
}
}
}]);
这里是html模型,文件名是ab.html
<input type="text" class="about-options" ng-model="testing" />
这里是要更新的视图,文件名是show.html
<h2 class="about-options">{{testing}}</h2>
ab.html 文件将作为模板加载到 jquery ui 对话框 中,而我的 show.html 文件在主页中
如果我删除
scope: {
testing: '='
},
控制台正在显示我正在输入的内容
更新 - 1
尝试了以下更改
testing: '=test'
在html中
<input type="text" class="about-options" ng-model="testing" />
<h2 class="about-options">{{test}}</h2>
【问题讨论】:
标签: angularjs angularjs-directive angularjs-scope