我在提交表单后更改页面的URL时遇到问题.
这是我的应用程序的流程:
$scope.onAfterSubmit设置位置的函数.问题是在设置位置后没有任何反应.我也试过设置位置参数/......不.我也试过不提交表格.什么都行不通.
我已经测试过以查看代码是否达到了onAfterSubmit函数(它的功能).
我唯一想到的是,函数的范围以某种方式被改变(因为它从一个指令中被调用),但是onAfterSubmit如果范围发生变化,它又如何调用呢?
这是我的代码
var Ctrl = function($scope, $location, $http) {
$http.get('/resources/' + $params.id + '/edit.json').success(function(data) {
$scope.resource = data;
});
$scope.onAfterSubmit = function() {
$location.path('/').replace();
};
}
Ctrl.$inject = ['$scope','$location','$http'];
Run Code Online (Sandbox Code Playgroud)
有人可以帮帮我吗?
当用户输入正确的用户名和密码时,我想重定向到另一个位置.但是当我$location.path('dashboard')在这里使用时,浏览器的URL被更改但是该页面没有被加载.当使用ctrl + R刷新我的页面或者点击浏览器的刷新图标然后加载适当的页面.
$http.post('/login', $scope.userInfo)
.success(function (data) {
//Check if the authentication was a success or a failure
//Successful POST here does not indicate success of authentication
if (data.status === "authentication success") {
//Proceed to load the dashboard for the user
$location.path('/dashboard');
} else if (data.status === "authentication error") {
//Inform user of the error
$scope.errorMessage = data.error;
$scope.showErrorMessage = true;
}
})
.error(function (error) {
$scope.errorMessage = "Error while attempting to authenticate. Check log.";
$scope.showErrorMessage = true; …Run Code Online (Sandbox Code Playgroud) angularjs ×2