I have Login page.

我有登录页面。

Login.html

的login.html

<ion-view view-title="Login" name="login-view">
  <ion-content class="padding">
      <div class="list list-inset">
          <label class="item item-input">
              <input type="text" placeholder="Username" ng-model="data.username">
          </label>
          <label class="item item-input">
              <input type="password" placeholder="Password" ng-model="data.password">
          </label>
      </div>
      <button class="button button-block button-calm" ng-click="login()">Login</button>
  </ion-content>
</ion-view>

When i click to login button login() method works in below

当我点击登录按钮时,login()方法在下面工作

LoginCtrl controller.

LoginCtrl控制器。

.controller('LoginCtrl', function ($scope, LoginService, $ionicPopup, $state, $location, $http) {
  $scope.login = function () {
    $http({
      method: 'GET',
      url: 'http://localhost:49431/api/values/GetUserInfo?username=' + $scope.data.username + '&password=' + $scope.data.password + ''
    }).then(function successCallback(response) {
      if (response.data.Status == true) { // Success
        $location.path('/HomePage/').search({ id: '1' }); // Problem here
      } else { // Fail
        var alertPopup = $ionicPopup.alert({
          title: 'Login failed!',
          template: 'Username or password is incorrect!'
        });
        $scope.data.username = "";
        $scope.data.password = "";
      }
    }, function errorCallback(response) {
      alert("error");
    });
  }
})

I use

我用

$location.path('/HomePage/').search({ id: '1' }); 

code in order to pass id parameter to HomePage.Html page.However neither location path pass parameter nor redirect page.Shortly location path is not working.

代码,以便将id参数传递给HomePage.Html页面。但是,无论位置路径传递参数还是重定向页面都没有。短暂的位置路径不起作用。

HomePageCtrl controller

HomePageCtrl控制器

.controller('HomePageCtrl', function ($scope, HomePageService, $state, $location, $cordovaCamera, $stateParams, $routeParams) {
    alert($routeParams.id + $stateParams.id);
}

app.js

app.js

.config(function ($stateProvider, $urlRouterProvider) {
  $stateProvider
    .state('HomePage', {
      url: '/HomePage',
      templateUrl: 'templates/HomePage.html',
      controller: 'HomePageCtrl'
    })
    .state('login', {
      url: '/login',
      templateUrl: 'templates/Login.html',
      controller: 'LoginCtrl'
    });
  $urlRouterProvider.otherwise('/login');
});

Question:

题:

How can i pass parameter to HomePageCtrl controller from LoginCtrl controller by using $location.path?

如何通过使用$ location.path从LoginCtrl控制器传递参数到HomePageCtrl控制器?

Any help will be appreciated.

任何帮助将不胜感激。

Thanks.

谢谢。

2 个解决方案

#1


2

Why you don't use $state instead of $location

为什么你不使用$ state而不是$ location

App.js :

App.js:

 .state('HomePage', {
             url: '/HomePage/:id',
             templateUrl: 'templates/HomePage.html',
             controller: 'HomePageCtrl'
  })

LoginCtrl:

LoginCtrl:

.controller('LoginCtrl', function ($scope, LoginService, $ionicPopup, $state, $location, $http) {

           $scope.login = function () {

            $http({
                method: 'GET',
                url: 'http://localhost:49431/api/values/GetUserInfo?username=' + $scope.data.username + '&password=' + $scope.data.password + ''
            }).then(function successCallback(response) {

                if (response.data.Status == true) { // Success

                    $state.go('HomePage',{id:'1'})

                }
                else { // Fail
                    var alertPopup = $ionicPopup.alert({
                        title: 'Login failed!',
                        template: 'Username or password is incorrect!'
                    });

                    $scope.data.username = "";
                    $scope.data.password = "";
                }

            }, function errorCallback(response) {
                alert("error");
            });
    }
    })

HomeCtrl :

HomeCtrl:

.controller('HomePageCtrl', function ($scope, HomePageService, $state, $location, $cordovaCamera, $stateParams, $routeParams) {

    alert($stateParams.id);
}

更多相关文章

  1. 代码点火-如何从控制器返回Json响应
  2. 角度服务和控制器共同范围
  3. AngularJS(1.5.8) - 如何直接从获取json对象的控制器中填充选择选
  4. 如何在rails中使用ajax将数据从控制器传递到视图
  5. Angular使用jQuery插件与外部控制器中的对象
  6. jQuery Ajax未能调用MVC 4控制器方法。
  7. 从json获取最大插槽并应用于控制器
  8. XGBoost中参数调优的完整指南(含Python-3.X代码)
  9. python传递列表作为函数参数

随机推荐

  1. 现在学c语言用什么软件
  2. 怎么精通C语言?
  3. c反射和序列化是什么
  4. c#用什么软件编程?
  5. c语言需要什么基础
  6. c语言 三种求回文数的算法
  7. asp文件用什么打开
  8. c语言怎么编译(详细示例)
  9. Unity 3D 浅谈Shader 运行时状态及渲染模
  10. c语言工程师的工作是什么