Javascript Can';t更新指令中的$scope值

Javascript Can';t更新指令中的$scope值,javascript,html,angularjs,Javascript,Html,Angularjs,当使用scope.$last完成ng repeat时,此指令触发: simpleSearchApp.directive('afterResults', function($document) { return function(scope, element, attrs) { if (scope.$last){ scope.windowHeight = $document[0].body.clientHeight; } }; }); 我正在尝试使用新值更新$scope.

当使用
scope.$last
完成
ng repeat
时,此指令触发:

simpleSearchApp.directive('afterResults', function($document) {
 return function(scope, element, attrs) {
   if (scope.$last){
    scope.windowHeight = $document[0].body.clientHeight;
   }
 };
});
我正在尝试使用新值更新
$scope.windowHeight
,但无法访问指令中的
$scope

My
ng repeat
HTML带指令:

 <div ng-show="items" class="ng-cloak" ng-repeat="item in items" after-results>
     {{item}}
 </div>

{{item}}

老实说,我也不明白为什么它没有更新。但更新控制器中变量的另一种方法是定义一个函数,该函数更新变量并从指令调用控制器中的函数。请看下面的例子,它可能会对您有所帮助

angular.module('app',[]).controller('MyController',['$scope',function($scope){
$scope.windowHeight=0;
$scope.updateWindowHeight=函数(高度){
$scope.windowHeight=高度;
}
}])
.directive('afterResults',函数($document){
返回函数(范围、元素、属性){
如果(范围$last){
scope.windowHeight=$document[0]。body.clientHeight;
scope.updateWindowHeight(scope.windowHeight);//在控制器中调用函数
}
};
});

{{item}}

{{“$scope.windowHeight=“+windowHeight}”