角:推项目列表不更新视图 [英] Angular: Push item to list doesn't update the view
问题描述
当我把一个项目一个数组,该视图不会刷新列表。
When I push an item to an array, the view won't refresh the list.
表:
<tbody id="productRows">
<tr data-ng-repeat="product in products | filter: search">
<td>{{ product.Code}}</td>
<td colspan="8">{{ product.Name}}</td>
</tr>
</tbody>
形式:
<form data-ng-submit="submitProduct()">
Code:
<br />
<input type="text" required data-ng-model="product.Code"/>
<br />
<br />
Naam:
<br />
<input type="text" required data-ng-model="product.Name"/>
<br />
<input type="submit" value="Opslaan" />
</form>
在submitProduct控制器:
submitProduct in controller:
$scope.submitProduct = function () {
console.log('before: ' + $scope.products.length);
$scope.products.push({Code: $scope.product.Code, Name: $scope.product.Name});
console.log('after:' + $scope.products.length);
console.log($scope.products);
$scope.showOverlay = false;
};
正如你所看到的,我登录了总项目的数组中,它的行为像我期望的那样。没有做什么,我想到的唯一的事情就是我的表的内容,这并不表明新值。
As you can see, I log the total items in the array and it behaves like I would expect. The only thing that doesn't do what I expect is the content of my table, that doesn't show the new value.
我有什么做的,所以新的行会显示在表格?
What do I have to do, so the new row is displayed in the table?
推荐答案
感谢您的回答和评论。问题是在另一个地方。在我的 routeProvider
我宣布一个控制器。我也有一个 NG-控制器
指令在我的股利。所以,我的控制器被执行两次。当我删除了 NG-控制器
指令,一切都只是工作,因为它应该是:)
Thanks for the answer and the comments. The problem was at another place. In my routeProvider
I had declared a controller. I also had a ng-controller
directive in my div. So my controller gets executed twice. When I removed the ng-controller
directive, everything was just working as it should be :)
这篇关于角:推项目列表不更新视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!