在角度,如何与$ location.path为$ http.post成功回调重定向 [英] In Angular, how to redirect with $location.path as $http.post success callback

查看:115
本文介绍了在角度,如何与$ location.path为$ http.post成功回调重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图发送一个帖子的PHP文件做一个简单的身份验证服务,我需要它装载在我的NG-查看主页时,局部的成功。

I am attempting to make a simple authentication service by sending a Post to a php file, I need it to load the home page partial on my ng-view when its successful.

这是我的尝试:

function loginCtrl($scope, $http, $location){
    $http.post(url,data).success(function(data){
        $location.path('/home');
    });
}

结果我的网址不断变化,但 NG-视图更新不及时。它更新当我手动刷新页面。

Results in my url changing but ng-view not updating. it updates when i manually refresh the page.

(路线得到了妥善的 $ routeProvider ,我已经测试配置了一个独立的函数不重定向这是一个回调和它的作品)

(routes have been configured properly at the $routeProvider, i have tested redirecting this with a standalone function not as a callback and it works )

我也试图定义 $ location.path('/家')作为一个函数,然后调用它仍然无法正常工作的回调。

I have also tried defining $location.path('/home') as a function and then calling it on the callback it still doesn't work.

我做了一些研究,发现了一些文章,指出这一点使用其他第三方插件发生的时候,我只加载angular.js

I did some research and found some articles stating this happens when using another third party plugin, I am only loading angular.js

任何见解或指点一下学习材料将是巨大的。

Any insights or pointers to some study material will be great

推荐答案

下面是从这篇文章<一的changeLocation例子href=\"http://www.yearofmoo.com/2012/10/more-angularjs-magic-to-supercharge-your-webapp.html#apply-digest-and-phase\">http://www.yearofmoo.com/2012/10/more-angularjs-magic-to-supercharge-your-webapp.html#apply-digest-and-phase

//be sure to inject $scope and $location
var changeLocation = function(url, forceReload) {
  $scope = $scope || angular.element(document).scope();
  if(forceReload || $scope.$$phase) {
    window.location = url;
  }
  else {
    //only use this if you want to replace the history stack
    //$location.path(url).replace();

    //this this if you want to change the URL and add it to the history stack
    $location.path(url);
    $scope.$apply();
  }
};

这篇关于在角度,如何与$ location.path为$ http.post成功回调重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆