gpt4 book ai didi

ionic-framework - 弹出确认 ionic 后如何导航到另一个页面

转载 作者:行者123 更新时间:2023-12-04 21:10:33 26 4
gpt4 key购买 nike

我正在尝试在 ionic 中为移动应用程序创建一个登录页面,在用户输入一些 ID 和密码后,它将导航到另一个页面。我尝试使用 state.go 和 location.path 但它不起作用。这是代码:

    angular.module('app.controllers', ['ionic','ui.router'])
.controller('loginCtrl', function($scope, $ionicPopup, $state) {
$scope.data ={};
$scope.submitData = function(){

if($scope.data.email && $scope.data.password){
var alertPopup = $ionicPopup.alert({
title: "Login Succesful",
template: "Welcome Back "
});
$state.go('stateHome');
}else{

var alertPopup = $ionicPopup.alert({
title: "Login Failed",
template: "Please check your credentials"
});
}
}
})
app.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('stateHome', {
url: '/Home',
views: {
'Home' :{
templateUrl : "templates/Home.html",
controller : 'HomeCtrl'

}
}
});

$urlRouterProvider.otherwise('/Setting');


})

我的 app.js 包含:
    angular.module('app', ['ionic', 'app.controllers', 'app.routes', 'app.services', 'app.directives'])

.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) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
});
})

知道如何解决这个问题吗?

最佳答案

尝试按如下方式修改您的文件。它应该工作。如果你觉得它很困惑,我可以详细说明。

应用程序.js

angular.module('app', ['ionic', 'app.controllers', 'app.routes', 'app.services', 'app.directives'])

.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) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
});
})

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

$stateProvider

.state('stateHome', {
url: '/Home',
templateUrl: 'templates/Home.html',
controller: 'HomeCtrl'
})

$urlRouterProvider.otherwise('/Setting');
})

Controller .js
angular.module('app.controllers', [])

.controller('loginCtrl', function($scope, $ionicPopup, $state, $location) {

$scope.data ={};
$scope.submitData = function(){

$scope.goToHomePage = function () {
$location.path("/Home");
};

if($scope.data.email && $scope.data.password){
var alertPopup = $ionicPopup.alert({
title: "Login Succesful",
template: "Welcome Back "
});
alertPopup.then(function(res) {
if(res) {
$scope.goToHomePage();
} else {
console.log('Do something else');
}
});

}else{

var alertPopup = $ionicPopup.alert({
title: "Login Failed",
template: "Please check your credentials"
});
}
}
})

关于ionic-framework - 弹出确认 ionic 后如何导航到另一个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35554362/

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