Can we attach ng-controller and ng-repeat to the same DOM element? Fiddle
Here is the HTML:
2条回答 被撕碎了的回忆 (楼主) 2021-02-06 04:44 You should break your controller into UserListController and UserController. The list of users should be part of UserListController and the each item can be managed by UserController Something like So the user controller becomes angular.module("myApp", []) .controller("UserController", ["$scope", function($scope) { $scope.selected = false; $scope.toggleSelectedUser = function() { $scope.user.selected = !$scope.selected; }; $scope.isSelectedUser = function() { return $scope.user.selected; }; }]); 0 讨论(0) 查看其它2个回答 发布评论: 提交评论 加载中... 验证码 看不清? 提交回复 热议问题
You should break your controller into UserListController and UserController. The list of users should be part of UserListController and the each item can be managed by UserController
UserListController
UserController
Something like
So the user controller becomes angular.module("myApp", []) .controller("UserController", ["$scope", function($scope) { $scope.selected = false; $scope.toggleSelectedUser = function() { $scope.user.selected = !$scope.selected; }; $scope.isSelectedUser = function() { return $scope.user.selected; }; }]); 0 讨论(0) 查看其它2个回答 发布评论: 提交评论 加载中... 验证码 看不清? 提交回复 热议问题
So the user controller becomes
angular.module("myApp", []) .controller("UserController", ["$scope", function($scope) { $scope.selected = false; $scope.toggleSelectedUser = function() { $scope.user.selected = !$scope.selected; }; $scope.isSelectedUser = function() { return $scope.user.selected; }; }]);