Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 更改指令中的局部作用域_Angularjs_Angularjs Directive_Angularjs Scope - Fatal编程技术网

Angularjs 更改指令中的局部作用域

Angularjs 更改指令中的局部作用域,angularjs,angularjs-directive,angularjs-scope,Angularjs,Angularjs Directive,Angularjs Scope,我需要一个具有本地范围的指令,该本地范围将按以下方式更新: var update; angular.module('docsTransclusionExample', []) .directive('myDialog', function() { return { restrict: 'E', scope: {}, templateUrl: 'my-dialog.html', link: function (scope, elemen

我需要一个具有本地范围的指令,该本地范围将按以下方式更新:

var update;
angular.module('docsTransclusionExample', [])
   .directive('myDialog', function() {
    return {
      restrict: 'E',
      scope: {},
      templateUrl: 'my-dialog.html',
      link: function (scope, element) {
        scope.name = 'Jeff';

          update = function(name){
              scope.name = name;
          };
      }
    };
  });
现在,来自外部的东西将调用update并传入一个名称。
但是,现在是(),名称不会在屏幕上更新。我错过了什么?有人能帮忙吗?谢谢

--编辑--

忘记添加-这是一种简化,但在某一点上,指令将订阅服务,而不是在单击按钮时调用函数,该服务将以相同的方式将数据推送到它。

因为您的更新函数不属于angular的范围,您需要触发一个作用域。$手动应用,以便在其他地方更新该值。将此添加到更新功能:

scope.$apply();

啊,太好了,虽然我在其他地方看到了,但我还是错过了那件小事。谢谢:)