我有一个我从父控制器打开的引导模式实例,现在我在复选框checkedValue
上添加了我试图从子控制器调用的方法,但我收到错误Cannot read property 'attuid' of undefined at ChildScope.$scope.checkedValue (newUserModal.controller.js:22)
任何想法我怎样才能在子控制器中调用方法?
newUserModal.html
<tr ng-repeat="user in userList track by $index">
<td st-ratio="20">{{user.attuid}}</td>
<td st-ratio="30">{{user.firstName}} {{user.lastName}}</td>
<td st-ratio="15" ng-bind-html="user.type"></td>
<td st-ratio="15">{{user.email}}</td>
<td><input type="checkbox" ng-model="user.selected" ng-click="checkedValue(user)"> </td>
<!--<td st-ratio="20" class="text-right">
<button type="button" ng-click="editUser($index, user)" class="btn btn-primary">
Approve
</button>
</td>-->
</tr>
parent.controller.js
$scope.newUserListModal = function () {
$scope.modalInstance = $uibModal.open({
templateUrl: 'app/access/accessModal/newUserModal.html',
controller: 'AccessModalCtrl',
size: 'lg'
});
$scope.modalInstance.rendered.then(function () {
$rootScope.$broadcast('show-user-list',$scope.userList);
});
/*$scope.modalInstance.result.then(function(selectedUsers) {
console.log(selectedUsers);
});*/
}
child.controller.js
angular.module('angularModelerApp')
.controller('AccessModalCtrl', function ($scope,$uibModalInstance,toastr) {
var selectedUsers = [];
$scope.$on('show-user-list',function(e,data){
$scope.userList = data;
});
$scope.checkedValue = function(user){
$scope.selectedUsers = $scope.selectedUsers || [];
if(user.selected){
$scope.selectedUsers.push({ attuid: $scope.user.attuid,
firstName: $scope.user.firstName,
lastName: $scope.user.lastName,
email:$scope.user.email
});
console.log($scope.selectedUsers);
}
};
});