使用angularjs设置范围进行ng-click

时间:2015-02-20 08:27:43

标签: angularjs

我使用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;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

只需使用

ng-click="$parent.chooseCustomer(customer)"

因为在ng-repeat中你的范围发生了变化