我只是试图在选择选项后运行ng-change上的函数后让状态更改为新模板。
一旦做出选择,我的函数运行正常,但在函数末尾调用的$ state.go()实际上并没有将状态更改为我想要导航到的下一个状态视图。
以下是我的代码(简化)。我想在“template / pages / addit / index.html”中选择和选项,运行一个函数,然后将状态更改为“template / pages / addit / edit.html”。
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');
});
添加-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);
}
});
模板/页/ 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>
答案 0 :(得分:4)
可能是$ state.go(&#39; app.addit.edit&#39;)会在您的控制器中执行此操作。你错过了提供整个州名。
答案 1 :(得分:2)
实际上,结果是app.js的一个问题我应该有:
.state('app.edit', {
url: "/addit/edit",
views: {
'menuContent': {
templateUrl: "templates/pages/addit/editphotos.html"
}
}
});
我以前做的是尝试为编辑&#39;创建状态。页面不包含在菜单内容&#39;
的子状态