我对 Angular 完全陌生,我发现做简单的事情对我来说并不那么明显?我有一个使用 ng-repeat 显示的项目列表。一旦单击该范围内的元素,我只想隐藏该元素。我想通过良好的做法以“角度”的方式来做......只是不确定那是什么。
这是html
<div ng-app="myApp">
<div ng-controller="FruitsCtrl">
<ul>
<li ng-repeat="fruit in fruits">
<p>{{fruit.name}}</p>
<button ng-click="hideMe()">hide li</button>
</li>
</ul>
</div>
</div>
这是我的js
var myApp = angular.module('myApp', []);
myApp.factory('Fruits', function () {
var Fruits = [{
name: "banana"
}, {
name: "watermelon"
}, {
name: "strawberry"
}];
return Fruits;
});
function FruitsCtrl($scope, Fruits) {
$scope.fruits = Fruits;
$scope.hideMe = function () {
alert('hide this li');
};
}
我在 jsfiddle 上有这个:http: //jsfiddle.net/hS5q8/2/
帮助或方向会很棒!谢谢!!