有木有大神会angularjs的,我有个问题搞不出来,求教
angular
.module('app')
.controller('SigninCtrl', function SigninCtrl($scope, $injector) {
var $http = $injector.get('$http')
var $state = $injector.get('$state')
var $timeout = $injector.get('$timeout')
var $stateParams = $injector.get('$stateParams')
var $location = $injector.get('$location')
var $window = $injector.get('$window')
var $FB = $injector.get('$FB')
var $popup = $injector.get('$popup')
var $session = $injector.get('$session')
var $config = $injector.get('$config')
$scope.user = { email: $location.search().email }
$scope.remember = true
$session.purge()
$scope.passwordSignin = function (e) {
if (undefined !== e && 13 !== e.which) return
$scope.validate()
if (!$scope.signinForm.$valid) return
$scope.isSigningin = true
$scope.signin()
}
$scope.validate = function () {
$scope.checkField('email')
$scope.checkField('password')
}
$scope.checkField = function (what) {
if (!$scope.signinForm[what].$valid) {
$timeout(function () {
$('.form input[name=' + what + ']').trigger('open')
})
}
}
$scope.closeErrors = function () {
$timeout(function () {
$('.form input').trigger('close')
})
}
$scope.$watch('user', function () {
$scope.apiError = false
$scope.closeErrors()
}, true)
$scope.fbSignin = function () {
$scope.isFetchingFacebook = true
$FB.getLoginStatus(function (res) {
if (res.status === 'connected') {
$scope.isFetchingFacebook = false
$scope.user.facebook_token = res.authResponse.accessToken
$scope.signin()
} else {
$FB.login().then(function (res) {
$scope.isFetchingFacebook = false
$scope.user.facebook_token = res.authResponse.accessToken
$scope.signin()
})
}
})
}
$scope.twitterSignin = function () {
$scope.isFetchingTwitter = true
$popup($scope, '/#/oauth?twitter_auth', 500, 600, function () {
$scope.isFetchingTwitter = false
var twitterAuth = $session.load().get('twitterAuth')
$session.purge()
$scope.user.twitter_token = twitterAuth.accessToken
$scope.user.twitter_token_secret = twitterAuth.accessTokenSecret
$scope.signin()
})
}
$scope.signin = function () {
$http
.post($config.api_uri + '/signin', $scope.user)
.success(function (data) {
$session.set('auth', data)
$scope.remember && $session.save()
$state.go('root.dashboard')
})
.error(function (data) {
$scope.apiError = data.error
$scope.user = { email: $location.search().email }
})
}
})
这里是代码,搞不懂的地方在 $scope.closeErrors = function () {
$timeout(function () {
$('.form input').trigger('close')
})
}
$scope.$watch('user', function () {
$scope.apiError = false
$scope.closeErrors()
}, true)
因为在之前有checkfiled这个方法去提示一些小错误了,这边又写这样是怎么搞
angular
.module('app')
.controller('SigninCtrl', function SigninCtrl($scope, $injector) {
var $http = $injector.get('$http')
var $state = $injector.get('$state')
var $timeout = $injector.get('$timeout')
var $stateParams = $injector.get('$stateParams')
var $location = $injector.get('$location')
var $window = $injector.get('$window')
var $FB = $injector.get('$FB')
var $popup = $injector.get('$popup')
var $session = $injector.get('$session')
var $config = $injector.get('$config')
$scope.user = { email: $location.search().email }
$scope.remember = true
$session.purge()
$scope.passwordSignin = function (e) {
if (undefined !== e && 13 !== e.which) return
$scope.validate()
if (!$scope.signinForm.$valid) return
$scope.isSigningin = true
$scope.signin()
}
$scope.validate = function () {
$scope.checkField('email')
$scope.checkField('password')
}
$scope.checkField = function (what) {
if (!$scope.signinForm[what].$valid) {
$timeout(function () {
$('.form input[name=' + what + ']').trigger('open')
})
}
}
$scope.closeErrors = function () {
$timeout(function () {
$('.form input').trigger('close')
})
}
$scope.$watch('user', function () {
$scope.apiError = false
$scope.closeErrors()
}, true)
$scope.fbSignin = function () {
$scope.isFetchingFacebook = true
$FB.getLoginStatus(function (res) {
if (res.status === 'connected') {
$scope.isFetchingFacebook = false
$scope.user.facebook_token = res.authResponse.accessToken
$scope.signin()
} else {
$FB.login().then(function (res) {
$scope.isFetchingFacebook = false
$scope.user.facebook_token = res.authResponse.accessToken
$scope.signin()
})
}
})
}
$scope.twitterSignin = function () {
$scope.isFetchingTwitter = true
$popup($scope, '/#/oauth?twitter_auth', 500, 600, function () {
$scope.isFetchingTwitter = false
var twitterAuth = $session.load().get('twitterAuth')
$session.purge()
$scope.user.twitter_token = twitterAuth.accessToken
$scope.user.twitter_token_secret = twitterAuth.accessTokenSecret
$scope.signin()
})
}
$scope.signin = function () {
$http
.post($config.api_uri + '/signin', $scope.user)
.success(function (data) {
$session.set('auth', data)
$scope.remember && $session.save()
$state.go('root.dashboard')
})
.error(function (data) {
$scope.apiError = data.error
$scope.user = { email: $location.search().email }
})
}
})
这里是代码,搞不懂的地方在 $scope.closeErrors = function () {
$timeout(function () {
$('.form input').trigger('close')
})
}
$scope.$watch('user', function () {
$scope.apiError = false
$scope.closeErrors()
}, true)
因为在之前有checkfiled这个方法去提示一些小错误了,这边又写这样是怎么搞