简体   繁体   English

使用ionic serve --lab命令运行项目时,$ state.go无法正常工作

[英]$state.go is not working when project is run with ionic serve --lab command

Hello I am working with ionic framework and I want to redirect to another page 您好,我正在使用Ionion框架,我想重定向到另一页

after successfully login .When I run project using command: 成功登录后。当我使用命令运行项目时:

ionic serve then $state.go working properly but when I run project using 离子服务然后$ state.go正常工作,但是当我使用

ionic serve --lab it is not working 离子服务--lab它不起作用

 .controller('AppCtrl', function($scope,$http, $ionicModal,$location,$state, $timeout) {

    // Form data for the login modal
    $scope.loginData = {};

    // Create the login modal that we will use later
    $ionicModal.fromTemplateUrl('templates/login.html', {
        scope: $scope
        }).then(function(modal) {
        $scope.modal = modal;
    });

    // Triggered in the login modal to close it
    $scope.closeLogin = function() {
        $scope.modal.hide();
    };

    // Open the login modal
    $scope.login = function() {
        $scope.modal.show();
    };

    // Perform the login action when the user submits the login form
    $scope.doLogin = function() {

        alert($scope.loginData.username);
        alert($scope.loginData.password);

        $http({
            method: 'POST',
            url: 'http://localhost/home_owner12/admin/api/login',
            data: {username:$scope.loginData.username,password:$scope.loginData.password},
            headers : {
            'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8'}
        })
        .then(function successCallback(response) 
        {

            if(response.data.length > 0)
            {

                 $state.go('app.search');
                 console.log('the state is '+$state.current);

            }
            else 
            {
                alert("Invalid email or pasword");
                ///$location.path('/search');

            }
        }, function errorCallback(response) 
        {
            alert("Invalid email pasword");
        });
    };
    })

here is state: 这是状态:

config(function($stateProvider, $urlRouterProvider) {
  $stateProvider

    .state('app', {
    url: '/app',
    abstract: true,
    templateUrl: 'templates/menu.html',
    controller: 'AppCtrl'
  })

 .state('app.search', {
    url: '/search',
    views: {
      'menuContent': {
        templateUrl: 'templates/search.html',
        controller: 'AppCtrl'
      }
    }
  });

and module 和模块

angular.module('starter', ['ionic', 'starter.controllers', 'ui.router'])

The app.search page's controller goes to AppCtrl in place. app.search页面的控制器将转到AppCtrl。

Because AppCtrl runs a second time, it is entering an infinite loop. 由于AppCtrl第二次运行,因此它进入了无限循环。

Replace the code with that 将代码替换为

config(function($stateProvider, $urlRouterProvider) {
          $stateProvider

          .state('app', {
            url: '/app',
            abstract: true,
            templateUrl: 'templates/menu.html',
            controller: 'AppCtrl'
          })

         .state('app.search', {
            url: '/search',
            views: {
              'menuContent': {
                templateUrl: 'templates/search.html',
                controller: 'SearchCtrl'
              }
            }
          });

and

 .controller('SearchCtrl', function($scope,$http,    $ionicModal,$location,$state, $timeout) {
............
.........
.......
 })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM