【发布时间】:2016-03-30 15:34:13
【问题描述】:
在我的代码中, location.path("#/") 不起作用我尝试了很多,但我不明白为什么它不起作用。有一个简单的逻辑,注册成功后弹窗关闭,通知栏插件会看到通知。
我从 4 小时就开始了。
注册
(function () {
'use strict'
/*
* Signup Controller
* @param {$scope} Object
* @return
*/
function SignupCtrl($scope, $location, $window, $timeout, UserService, notifications) {
//$scope.captchaError=false;
//$scope.passwordPattern = '((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{8,})';
$scope.doRegistration = function () {
console.log("form validation status:" + $scope.frmSignup.$valid);
if (true === $scope.frmSignup.$valid) {
console.log("validation successfully executed");
UserService
.register($scope.user)
.error(function () {
angular.element('#btnCancelSignup').triggerHandler('click');
notifications.showError({
message: 'Ooops! there is error occured, please try again.',
hideDelay: 1500, //miliseconds
hide: true // boolean
});
$location.path("#/");
})
.then(function (res) {
if (res.data.status === 1) {
console.log("success in registration");
angular.element('#btnCancelSignup').trigger('click');
notifications.showSuccess({
message: 'Please check your email to complete registration.',
hideDelay: 1500, //miliseconds
hide: true // boolean
});
$location.path("#/");
if(!$scope.$$phase) $scope.$apply();
}
Recaptcha.reload();
});
}
}
}
angular
.module('AppWhizbite')
.controller('SignupCtrl', ['$scope', '$location', '$window', '$timeout', 'UserService', 'notifications', SignupCtrl]);
}());
【问题讨论】:
-
尝试编辑哈希而不是路径。
$location.hash('/') -
@LuisMasuelli:谢谢你的回答。但它不起作用。它在 url 中附加如下:localhost:1000/#/#%2F
-
请注意,我使用了 '/' 而不是 '#/'。
-
是的,我和你描述的一样。
-
否则尝试 path('/') 而不是使用 #/