AngularJS指令的link功能更改隔离范围数据未反映在UI中.
这是一个例子:
var myApp = angular.module('myApp', []);
myApp.directive('myDirective', function () {
return {
restrict: 'A',
template: '<span>Title: {{myParams.title}}</span>',
scope: {
myParams: '='
},
link: function ($scope) {
// the new value is not reflected in ui
$scope.myParams.title = 'this is myDirective';
}
};
});
Run Code Online (Sandbox Code Playgroud)
HTML:
<div my-directive my-params="{title: 'this is title'}"></div>
Run Code Online (Sandbox Code Playgroud)
我想要显示HTML页面,this is myDirective但实际上它是this is title.
另外,你能解释为什么它会这样显示.谢谢