我正在尝试编写一个函数,该函数使我可以在单击按钮时删除项目,但我认为我对该函数感到困惑-我可以使用$digest
吗?
HTML和app.js:
<ul ng-repeat="bday in bdays">
<li>
<span ng-hide="editing" ng-click="editing = true">{{bday.name}} | {{bday.date}}</span>
<form ng-show="editing" ng-submit="editing = false">
<label>Name:</label>
<input type="text" ng-model="bday.name" placeholder="Name" ng-required/>
<label>Date:</label>
<input type="date" ng-model="bday.date" placeholder="Date" ng-required/>
<br/>
<button class="btn" type="submit">Save</button>
<a class="btn" ng-click="remove()">Delete</a>
</form>
</li>
</ul>
$scope.remove = function(){
$scope.newBirthday = $scope.$digest();
};
remove()
以ng-click
您拥有的方式没有上下文。在标记中需要更多详细信息,以显示要删除的内容以及该内容是否在ng-repeat
其中,或者要删除的内容来自何处,或者您想要什么行为remove()