I'm using AngularJS and Ionic to create hybrid applications and I'm having a question. I created a project with template blank, in index.html it was created the tag ion-content
that I believe eh where it renders the other pages. The problem is that I can not make these other pages open in this content. In my case I want to open the pages main.html
and login.html
in <ion-content name="mainContent">
.
How to do this?
I'm trying like this.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
<!-- controllers -->
<script src="js/controllers/MainCtrl.js"></script>
<!--directives-->
</head>
<body ng-app="starter" ng-controller="MainCtrl" animation="slide-left-right-ios7">>
<ion-pane>
<ion-header-bar class="bar-stable">
<h1 class="title">Ionic Blank Page</h1>
</ion-header-bar>
<ion-content class="padding" name="mainContent">
</ion-content>
</ion-pane>
</body>
</html>
app.js
angular.module('starter', ['ionic'])
.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){
$stateProvider
.state('main', {
url: "/main",
replace:true,
views:{
'mainContent':{
templateUrl: 'templates/main.html',
}
},
controller: 'MainCtrl',
})
.state('login', {
url: '/login',
views: {
'mainContent': {
templateUrl: 'templates/login.html'
}
}
});
$urlRouterProvider.otherwise('/main');
});
main.html
<ion-content>
<ion-pane>
<div class="principal">
<button class="button button-block button-positive" ng-click="loginFacebook();">
Login by Facebook
</button>
<button class="button button-block button-assertive" ng-click="goTo('templates/login.html');">
Login
</button>
<button class="button button-block button-assertive" ng-click="goTo('templates/login.html');">
Add Login
</button>
<a href="#/login">Go to login</a>
</div>
</ion-pane>
</ion-content>
login.html
<ion-content>
<ion-pane>
<div class="list list-inset">
<label class="item item-input">
<input type="text" placeholder="Username" ng-model="data.username">
</label>
<label class="item item-input">
<input type="password" placeholder="Password" ng-model="data.password">
</label>
</div>
<button class="button button-block button-calm" ng-click="login()">Login</button>
</ion-pane>
</ion-content>