Html 如果使用push填充数组,则ng repeat不起作用

Html 如果使用push填充数组,则ng repeat不起作用,html,angularjs,Html,Angularjs,ng repeat在创建静态数组时有效,但在动态创建数组时无效 HTML 填充数组但在HTML中不呈现任何内容的代码 $scope.items = ["a", "b", "c"]; $scope.items = []; $scope.items.push("a"); $scope.items.push("b"); $scope.items.push("c"); 当我在调试器$scope.items中查看数组时,应该添加这一点。它只是不在HTML中呈现。考虑到摘要循环的工作方式,最好知道您在

ng repeat
在创建静态数组时有效,但在动态创建数组时无效

HTML

填充数组但在HTML中不呈现任何内容的代码

$scope.items = ["a", "b", "c"];
$scope.items = [];
$scope.items.push("a"); 
$scope.items.push("b");
$scope.items.push("c");

当我在调试器
$scope.items
中查看数组时,应该添加这一点。它只是不在HTML中呈现。

考虑到摘要循环的工作方式,最好知道您在什么时候执行此$scope项填充。无论您如何填充阵列,以下内容都会起作用:

angular.module('app',[])
角度.module('app').controller('DemoController',['$scope',function($scope){
$scope.items=[];
$scope.items.push(1);
$scope.items.push(2);
$scope.items.push(3);
}]);

{{item}}

谢谢大家的帮助。我正在注入$scope并正确使用它。我的问题是,我的数组中不时有重复的条目。将我的HTML更改为

<div ng-repeat="item in items track by $index">{{ item}}</div>
{{item}
已修复该问题。

能否创建一个演示该问题的示例?这应该是可行的,我认为视图没有更新的唯一原因是,您正在Angular的摘要周期之外将项目推到数组上。
<div ng-repeat="item in items track by $index">{{ item}}</div>