gpt4 book ai didi

javascript - ionic 如何以编程方式返回状态

转载 作者:太空狗 更新时间:2023-10-29 16:35:37 26 4
gpt4 key购买 nike

我有一个返回按钮,当我点击 ng-click='goBack()' 时。我可以在浏览器中看到从 http://app:8888/#/main/payments 更改的 url至 http://app:8888/#/main/products/7这是我想返回的正确路径,但问题是 View 不会在那里转换。

我必须点击刷新按钮才能到达那里或在 $ionicHistory.goBack(); 之后执行 window.location.reload。

我不想重新加载整个页面我想将该 View 转换为上一个 View 。

这是我的html

        <div class="row">
<div class="col col-25">
<button ng-click="goBack()" class="button button-large button-block button-royal">Go Back</button>
</div>
</div>

这是我的 Controller

.controller('paymentsController', function($scope, $localStorage, $log, $state, $window, $ionicHistory){

$scope.goBack = function(){

$ionicHistory.goBack();

}


})

这是我的 app.js 我不知道这是否有帮助。

// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services', 'ngStorage'])

.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})

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

//$ionicConfigProvider.views.transition('none');

$urlRouterProvider.otherwise('/');

$stateProvider

.state('login',{
url: '/',
templateUrl: 'templates/login.html',
controller: 'loginController'
})

.state('main', {
url: '/main',
templateUrl: 'templates/main.html',
controller: 'mainController',
abstract: true
})

.state('main.categories', {
url: '/categories',
views: {
'categories': {
templateUrl: 'templates/categories.html',
controller: 'categoriesController'
}
}
})

.state('main.products', {
url: '/products/:productId',
views: {
'products': {
templateUrl: 'templates/products.html',
controller: 'productsController'
}
}
})

.state('main.payments', {
url: '/payments',
views: {
'payments': {
templateUrl: 'templates/payments.html',
controller: 'paymentsController'
}
}
})

})

最佳答案

从你想返回的 Controller 调用它..

var backCount = 1;
$rootScope.$ionicGoBack();
$rootScope.$ionicGoBack = function(backCount) {
$ionicHistory.goBack(backCount);
};

关于javascript - ionic 如何以编程方式返回状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31737127/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com