AngularJS 指令模板未更新

AngularJS Directive template not updating

尽管有手表,但模板指令没有更新。这里缺少什么?手表里面的日志确实有效,那么为什么 Html 也没有改变?

college.directive('showTeacherInfo', function ($http) {
    return {
        restrict: 'E',
        transclude: true,
        scope: {
            'subject': '@subjectId'
        },
        template: '<div> {{ scope.teacher | json }} </div>',
        link: function (scope, element, attrs) {
            console.log('Retrieving teacher information ...');
            scope.teacher = {}; 

            var getTeacherInfo = function () {
                if (!isNaN(scope.subject)) {
                    $http(
                        {
                            method: 'GET',
                            url: '/Subject/GetTeacherOfSubject',
                            params: { id: scope.subject }
                        }).then(function successCallback(response) {
                            if (response.data) {
                                scope.teacher = response.data;
                            }
                        }, function errorCallback(response) {
                            console.log(response);
                        });
                }
            };                
            attrs.$observe('subjectId', function () {
                getTeacherInfo();
            });
            scope.$watch('teacher', function () {
                console.log(scope.teacher);
            });
        }
    }
});

并且在 html

<show-teacher-info subject-id="{{currentSubjectID}}"></show-teacher-info>

ERRONEOUS

template: '<div> {{ scope.teacher | json }} </div>',

更好

template: '<div> {{ teacher | json }} </div>',

AngularJS 表达式在范围上下文中计算。无需将其添加到 HTML.