我想问一下如何列出我在列表中点击的内容......示例代码如下所示
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js">
</script>
<title>Belajar Angular</title>
<script type="text/javascript">
var app = angular.module('tesapp', []);
app.controller('tesCtrl', function($scope,$http){
$scope.DapatkanItem = function(){
$http.get('/someurl').success(function(data){
$scope.item = data;
});
};
$scope.DapatkanItem();
$scope.namaItem = [];
$scope.klikIseng = function(item){
$scope.namaItem.push(item.name);
};
$scope.tampilKlikItem = function(){
}
});
app.filter('regex', function() {
return function(input, field, regex) {
var patt = new RegExp(regex);
var out = [];
for (var i = 0; i < input.length; i++){
if(patt.test(input[i][field]))
out.push(input[i]);
}
return out;
};
});
</script>
</head>
<body ng-app="tesapp" ng-controller="tesCtrl">
<h1>Mencoba Filtering</h1>
<h2>Mencoba ng-click</h2>
<div class="col col-4">
<label class="select">
<select name="gender" ng-model="alfabet">
<option value="^" selected disabled>Alphabet</option>
<option value="^(A|a)">A</option>
<option value="^(B|b)">B</option>
<option value="^(C|c)">C</option>
</select>
</label>
</div>
<ul ng-repeat="name in namaIt = track by $index">
<li>{{name}}</li>
</ul>
<div ng-switch="alfabet">
<div ng-switch-default>
<ul ng-repeat="tes in item.stores | regex:'name':alfabet | orderBy: 'preparation' | orderBy: 'name'">
<input type="button" ng-click="klikIseng(tes)" value="klik gue">
<li ng-if="tes.preparation == ''" >{{tes.name}} kosong</li>
<li ng-if="tes.preparation == '1'">{{tes.name}} satu</li>
<li ng-if="tes.preparation == '2'">{{tes.name}} dua</li>
<li ng-if="tes.preparation == '3'">{{tes.name}} tiga</li>
</ul>
</div>
<div ng-switch-when="1">
<ul ng-repeat="tes in item.stores | orderBy: 'preparation'">
<li>{{tes.name}}</li>
</ul>
</div>
</div>
</body>
</html>
我想列出我点击的内容,如果我使用普通的Json,它可以正常工作,因为我可以直接点击ng-click功能......
有没有解决方案?
非常感谢