2
我想在角度點擊一個可點擊的列表,點擊該項目後,它應該在控制器中觸發一個我想要操作該項目的功能。 的代碼是:有角度的可點擊列表
<h2>User List</h2>
<ul ng-repeat="item in items">
<li ng-repeat="(key, val) in item">
<ul>
<li>
<div ng-click="getUserChat(key)">
<a>{{key}}</a>
</div>
</li>
</ul>
</li>
</ul>
在控制器:
chatApp.controller('chatController', ['$scope', '$rootScope','$state', '$http' , function($scope, $rootScope, $state, $http) {
$scope.init = function(){
$http.get("http://127.0.0.1:8000/user_list/").success(function(data) {
$scope.items = data;
console.log($scope.items);
});
};
$scope.getUserChat = function(selectedFriend){
$rootScope.selectedFriend = selectedFriend;
console.log($rootScope.selectedFriend);
}
}]);
不過的console.log沒有顯示任何東西,這是相關聯的功能getUserChat不叫。它也沒有在控制檯中顯示任何錯誤。
你可以提供一個證明你的問題的jsfiddle,因爲你的方法是正確的。應該沒有問題,就像在這個小提琴中看到的一樣:http://jsfiddle.net/cemozer/nPRRB/2/ –