我使用AngularJS实施了ng-click
,但似乎无法正常工作,我想在ng-repeat
...
我的代码:
var app = angular.module("GestiawebApp", []);
app.controller("CustomerController", function($scope, $http) {
$http.get('/api/eccustomer').success(function(data, status, headers, config) {
$scope.customers = data;
});
$scope.chooseCustomer = function(customer){
$scope.choosingCustomer = customer;
};
});

<input type="text" class="form-control" name="search" ng-model="searchCustomer" required placeholder="Prénom ou nom du client" autocomplete="off">
<ul ng-repeat="customer in customers | filter:searchCustomer | limitTo:5">
<li>{{customer.firstname}} <a href="#" ng-click="chooseCustomer(customer)">Choisir</a></li>
</ul>
<p>{{choosingCustomer.firstname}}</p>
&#13;
答案 0 :(得分:0)
只需使用
ng-click="$parent.chooseCustomer(customer)"
因为在ng-repeat中你的范围发生了变化