[英]ng-click not working on table row in a directive
這是此問題的后續措施: 如何將我的模型添加到指令中?
該指令正在顯示數據,但是ng-click不會執行任何操作。
我的部分頁面現在看起來像這樣:
<div>selected user:{{selectedUser.UserName}} </div>
<div user-list data-users="users"></div>
現在我的指令如下所示:
tsUui.directive('userList', function(){
return{
restrict: 'A',
template: '<table>'+
'<tr>'+
'<th>User Name</th>'+
'<th>First Name</th>'+
'<th>Last Name</th>'+
'<th>Email Address</th>'+
'</tr>'+
'<tr ng-repeat="user in users" ng-click="selectUser(user)">'+
'<td>{{user.UserName}}</td>'+
'<td>{{user.FirstName}}</td>'+
'<td>{{user.LastName}}</td>'+
'<td>{{user.Email}}</td>'+
'</tr>'+
'</table>',
scope:{
selectedUser: '=',
users: '='
},
link: function (scope, elem, attrs){
scope.selectUser = function(user){
console.log("hi");
selectedUser=user;
};
}
}
});
數據正確顯示,但是當我單擊一行時,什么都沒有發生:沒有控制台日志,所選用戶沒有更改...什么都沒有。 我究竟做錯了什么?
編輯:控制台正在記錄它,但所選的用戶綁定不會更改...
顯然,您必須這樣做:
scope.selectedUser=user;
我也改變了部分:
<div>selected user:{{selection.UserName}} </div>
<div user-list data-users="users" selected-user="selection"></div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.