我有service.js,其中进行身份验证。成功服务回调函数从controller.js执行
service.js:
'use strict';
angular.module('Authentication')
.factory('AuthenticationService', ['$http', '$cookieStore', '$rootScope','$timeout', '$location', '$window',
function ($http, $cookieStore, $rootScope, $timeout, $location, $window) {
var service = {};
service.Login = function (username, password, callback) {
$http.post('..json', {
headers: {
username: username,
password: password
}
})
.success(function (data, status, headers, config) {
$timeout(function () {
callback(status);
}, 1000);
});
};
return service;
}])
controller.js:
'use strict';
angular.module('Authentication').controller('LoginController', ['$scope', '$rootScope', '$location', 'AuthenticationService', '$http', '$timeout', '$window',
function ($scope, $rootScope, $location, AuthenticationService, $http, $timeout, $window) {
**$scope.name=true;**
$scope.login = function () {
AuthenticationService.Login($scope.username, $scope.password, function (response) {
if (response === 'Success') {
$http.get('..json').success(data,status,headers,config){
**$scope.value=true;**
})
} else {
alert("Error");
}
});
};
}]);
HTML:
我有2个复选框与来自controller- $ scope.name和$ scope.value的两个$ scope变量链接
<input type="checkbox" ng-checked="name"> abc
<input type="checkbox" ng-checked="value">xyz
现在,由于两个$ scope变量都设置为true,因此最初应检查两个复选框....但是选中$ scope.name复选框并取消选中$ scope.value
有关为什么会发生这种情况的任何想法以及如何根据$ scope.value最初检查第二个复选框