gpt4 book ai didi

javascript - 如何在 ionic 中的两个页面之间导航

转载 作者:行者123 更新时间:2023-11-28 07:14:56 25 4
gpt4 key购买 nike

我正在研究 ionic 框架。我不知道如何在两个页面之间导航。我试图使用侧面菜单模板使用 ionic 创建一个登录页面。这是 login.html 的代码

<ion-view view-title="Login">
<ion-header-bar>
<h1 class="title">Login</h1>
</ion-header-bar>
<ion-content>
<form ng-submit="doLogin()">
<div class="list">
<label class="item item-input item-stacked-label">
<span class="input-label">Username</span>
<input type="text" placeholder="Email or Phone">
</label>
<label class="item item-input item-stacked-label">
<span class="input-label">Password</span>
<input type="text" placeholder="Password">
</label>
<label class="item">
<button class="button button-block button-positive" type="submit">Log in</button>
</label>
<label class="item">
<span class="input-label">New user?</span>
<a class="button ion-plus-round" href="#/app/signup">Signup</a>
</label>

</div>
</form>
</ion-content>
</ion-view>

在 app.js 中:-

.state('app.login', {
url: "/login",
views: {
'menuContent': {
templateUrl: "templates/login.html",
controller: 'LoginCtrl'
}
}
})
.state('app.signup', {
url: '/signup',
views: {
'menuContent': {
templateUrl: 'templates/signup.html',
controller: 'LoginCtrl'
}
}
})

我将登录按钮放在 menu.html 中,其余部分都相同

 <ion-item nav-clear menu-close href="#/app/login">
Login
</ion-item>

当我点击菜单时,登录按钮可以工作,但登录页面中的注册按钮不起作用。你能帮助我吗?我是 ionic 和 angularjs 的新手

最佳答案

这应该有帮助,

<ion-view view-title="Login" name="loginView">
<ion-header-bar>
<h1 class="title">Login</h1>
</ion-header-bar>
<ion-content>
<form ng-submit="doLogin()">
<div class="list">
<label class="item item-input item-stacked-label">
<span class="input-label">Username</span>
<input type="text" placeholder="Email or Phone">
</label>
<label class="item item-input item-stacked-label">
<span class="input-label">Password</span>
<input type="text" placeholder="Password">
</label>
<label class="item">
<button class="button button-block button-positive" type="submit">Log in</button>
</label>
<label class="item">
<span class="input-label">New user?</span>
<a class="button ion-plus-round" ui-sref="app.signup">Signup</a>
</label>

</div>
</form>
</ion-content>
</ion-view>

你的路由应该是,

.state('app.login', {
url: "/login",
views: {
'loginView': {
templateUrl: "templates/login.html",
controller: 'LoginCtrl'
}
}
})
.state('app.signup', {
url: '/signup',
views: {
'signupView': {
templateUrl: 'templates/signup.html',
controller: 'LoginCtrl'
}
}
})

您的登录按钮,

 <ion-item nav-clear menu-close ui-sref="app.login">
Login
</ion-item>

UI-Router 由 AngularJS 和 Ionic 使用。所以考虑使用ui-sref属性。这还有一个优点,显然,当您使用例如 ui-sref="app.login" 时,您的父状态仍然绑定(bind)到“app” 。不要使用href在处理 Angular 时。您有一个 Angular 选项,即 ng-href .

添加<ion-view view-title="Signup" name="signupView">注册页面

希望这有帮助

关于javascript - 如何在 ionic 中的两个页面之间导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30935357/

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