【发布时间】:2015-08-22 12:27:09
【问题描述】:
我只是想在 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');
});
add-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>
【问题讨论】:
-
换个网址有用吗?
标签: javascript angularjs ionic-framework