简体   繁体   English

$ state.go()在没有错误的情况下运行但实际上并不适用于Ionic

[英]$state.go() runs with no errors but doesn't actually work w/ Ionic

I'm simply trying to get the state to change to a new template after running a function on ng-change, from a selection of options. 我只是试图在选择选项后运行ng-change上的函数后让状态更改为新模板。

My function runs fine once a selection is made, but the $state.go() that is called at the end of the function doesn't actually change the state to the next state view I want to navigate to. 选择完成后,我的函数运行正常,但在函数末尾调用的$ state.go()实际上并没有将状态更改为我想要导航到的下一个状态视图。

Below is my code (simplified). 下面是我的代码(简化)。 I want to select and option in "template/pages/addit/index.html", run a function, then change state to "template/pages/addit/edit.html". 我想在“template / pages / addit / index.html”中选择和选项,运行一个函数,然后将状态更改为“template / pages / addit / edit.html”。

app.js: app.js:

angular.module('starter', ['ionic','firebase'])

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

.state('app', {
url: "/app",
abstract: true,
templateUrl: "templates/pages/menu/index.html",
controller: 'AppController'

.state('app.addit', {
url: "/addit",
views: {
  'menuContent': {
    templateUrl: "templates/pages/addit/index.html",
    controller: 'AddItController'
  }
}})

.state('app.addit.edit', {
url: "/edit",
views: {
    templateUrl: "edit.html",
    controller: 'EditItController'
}
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/app/addit');
});

add-it-controller.js: 添加-IT-controller.js:

angular.module('starter')
.controller('AddItController', function($scope, $state, addInventory){

$scope.selectNum = function (num) {
  addInventory(num) //works fine
  $state.go('addit.edit');//doesn't actually change the state
  console.log('the state is '+$state.current);

}
});

templates/pages/addit/index.html: 模板/页/ ADDIT / index.html的:

   <ion-view view-title="Addit">
  <ion-content>
  <div class="list card">

       <label class="item item-input item-select">
          <div class="input-label">
            How many?
          </div>
          <form >
            <select ng-change='selectNum(num)' ng-model="num"  required>

              <option  value='1'  selected>1</option>
              <option  value='2' >2</option>

            </select>
        </form>
      </label>
  </ion-content>
</ion-view>

May be $state.go('app.addit.edit') will do the trick in your controller. 可能是$ state.go('app.addit.edit')将在您的控制器中执行此操作。 You missed to provide the whole statename. 你错过了提供整个州名。

Actually, it turned out to be an issue with app.js where I should have had: 实际上,它原来是app.js的一个问题,我应该有:

 .state('app.edit', {
    url: "/addit/edit",
    views: {
      'menuContent': {
        templateUrl: "templates/pages/addit/editphotos.html"
      }
    }
  });

What I was doing before was trying to create the state for the 'edit' page without including it as a sub-state of 'menuContent' 我之前做的是尝试为“编辑”页面创建状态,而不将其作为'menuContent'的子状态包含在内

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

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