I am working on ionic framework.I dont know how to navigate between two pages.I was trying to create a login page using ionic using side menu template.Here goes the code for 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>
In 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'
}
}
})
I put the login button in menu.html like this rest all being same
<ion-item nav-clear menu-close href="#/app/login">
Login
</ion-item>
Login button is working when i click in menu but Signup button is not working in login page.Can u help me?I am new to ionic and angularjs
Remove attribute "href" and add ui-sref="app.signup"... Hopefully it'll resolve issue.
Also in routing configuration, change views object name "menuContent" for singup.
.state('app.login', {
url: "/login",
views: {
'menuLogin': {
templateUrl: "templates/login.html",
controller: 'LoginCtrl'
}
}
})
.state('app.signup', {
url: '/signup',
views: {
'menuSingup': {
templateUrl: 'templates/signup.html',
controller: 'LoginCtrl'
}
}
})
This should help,
<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>
your routing should be,
.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'
}
}
})
your login button,
<ion-item nav-clear menu-close ui-sref="app.login">
Login
</ion-item>
UI-Router is used by AngularJS and Ionic. So consider using ui-sref
attribute.
This has one more advantage, oviously your parent state remains bound to 'app' when you use say for example, ui-sref="app.login"
. Do not use href
when dealing with Angular. You have an Angular option for that, which is ng-href
.
add <ion-view view-title="Signup" name="signupView">
for signUp page
hope this helps