相关疑难解决方法(0)

AngularJS $位置不改变路径

我在提交表单后更改页面的URL时遇到问题.

这是我的应用程序的流程:

  1. 路由已设置,URL被识别为某个表单页面.
  2. 页面加载,控制器设置变量,指令被触发.
  3. 触发了一个特殊的表单指令,它使用AJAX执行特殊的表单提交.
  4. 在执行AJAX之后(Angular不处理AJAX)然后触发回调并且指令调用$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)

有人可以帮帮我吗?

angularjs

124
推荐指数
4
解决办法
13万
查看次数

$ location.path不起作用

当用户输入正确的用户名和密码时,我想重定向到另一个位置.但是当我$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

18
推荐指数
3
解决办法
3万
查看次数

标签 统计

angularjs ×2