小编fio*_*say的帖子

为什么在指令的链接功能中对$ scope进行的更改未在UI上反映出来?

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.

另外,你能解释为什么它会这样显示.谢谢

javascript angularjs angularjs-directive

4
推荐指数
1
解决办法
125
查看次数