【发布时间】:2014-02-08 03:02:32
【问题描述】:
我对 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/
帮助或指导会很棒!谢谢!!
【问题讨论】:
标签: javascript angularjs angularjs-scope angularjs-ng-repeat ng-hide