我有一个包含2个键和值的JSON对象数组。此数组填充在md-list中以显示其内容。但是,当我尝试删除列表中的行时,它不会删除列表UI中的行。
以下是一个简化示例:
<md-list>
<md-subheader class="md-no-sticky">Learning Center Activity Name</md-subheader>
<md-list-item class="md-2-line"
ng-repeat="learningCenterActivityName in $parent.mondayLearningCenterActivityNameList track by $index"
ng-hide="$parent.mondayLearningCenterActivityNameList[$index]==undefined">
<div class="md-list-item-text compact">
<h3>{{learningCenterActivityName}}</h3>
<md-button class="md-raised md-primary" flex="none"
ng-click="deleteLearningCenterListItem($index)">x
</md-button>
</div>
<md-divider></md-divider>
</md-list-item>
</md-list>-->
控制器代码:
$scope.deleteLearningCenterListItem = function(index) {
delete $scope.mondayLearningCenterActivityNameList[index];
};
答案 0 :(得分:0)
使用array.splice
代替delete
,AngularJS将更新:
$scope.deleteLearningCenterListItem = function(index) {
$scope.mondayLearningCenterActivityNameList.splice(index, 1);
};