$ location.path无法在angularjs中工作

时间:2017-05-19 07:05:08

标签: php angularjs

$ location.path从php成功返回后没有重定向。从php页面返回的数据不为空。没有问题的PHP文件,它返回正确的数据。问题是$ location.path不工作我推荐了很多网站,但我找不到解决方案帮助我..

angular.module(MyApp).controller(Part3Controller, function ($scope, LoginService) {
                $scope.IsLogedIn = false;
                $scope.Message = '';
                $scope.Submitted = false;
               $scope.IsFormValid = false;

               $scope.MyLogin = {
                        USER_ID:'' ;
                        Password: '';
                };

            //Check is Form Valid or Not // Here f1 is our form Name
            $scope.$watch(f1.$valid, function (newVal) {
                   $scope.IsFormValid = newVal;
             });

            $scope.Login = function () {
                  $scope.Submitted = true;
                  if ($scope.IsFormValid) {
                      LoginService.GetUser($scope.MyLogin).then(function (d) {
                            if (d.data.USER_ID != null) {
                               $scope.IsLogedIn = true;
                               $location.Path(/LandingPage/FetchMenu);
                                                }
                                              else {
                                                     alert('Invalid Credential!');
                                             }
                                   });
                              }
                       };
              })
       .factory('LoginService, function ($http) {
                           var fac = {};
                           fac.GetUser = function (d) {
                                 return $http({
                                         url:/Data/UserLogin,
                                    method: POST,
                                  data: JSON.stringify(d),
                                headers: {content-type:application/json}
                            });
                        };
            return fac;
       });

1 个答案:

答案 0 :(得分:0)

您尚未注入$ location:

angular.module(MyApp).controller(Part3Controller,
  function ($scope, LoginService) {

应该是:

angular.module(MyApp).controller(Part3Controller,
  function ($location, $scope, LoginService) {