我是angularjs的新手。面对一个问题,像下面 我的标记是这样的:Angularjs范围更新问题
<div class="data-list">
<ul ng-repeat="client in clients | orderBy:orderProp | filter:query">
<li><a ng-click="update(client)" data={{client.id}} href="#">{{client.name}}</a></li>
</ul>
</div>
<div class="clientId">
{{clientId}}
</div>
而且我的控制器是这样的:
function ClientListCtrl($scope, $http) {
$http.get('/dummy-data/clients.json', {
cache: false
}).success(function (data) {
$scope.clients = data.clients;
});
$scope.activeClient = {};
$scope.update = function (selectedClient) {
$scope.activeClient = angular.copy(selectedClient);
console.log($scope.activeClient);
}
console.log("after click");
console.log($scope.activeClient);
// for sorting list
$scope.orderProp = '-numberOfUsers';
}
我想,当用户点击“客户名称”,{{clientId}}
将被更新,但范围更新它自我。并返回{}
(空白对象)。
如何在点击客户端名称后获得{{clientId}}?
在此先感谢。
嘿,感谢的jsfiddle,但在我的代码它不是wroking。我的标记是像http://jsfiddle.net/YcP9S/ – arnold 2013-05-14 14:39:21
看到http://jsfiddle.net/YcP9S/1/是你的标记(我只添加ng-app div)与我的js。它工作正常。检查你的js或粘贴在jsfiddle看看 – pbaris 2013-05-14 14:44:02