Open pages in content?

1

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>
    
asked by anonymous 08.11.2015 / 17:24

1 answer

0

Ionic uses the ui-router to navigate between states. States are usually composed of a view (template html) and a controller (js).

There are several ways to navigate between states, for example using ui-sref= instead of href= . Or programmatically (in the controllers) injecting $state into the controller and calling $state.go('myState')

You can set the default state at configuration time, like this:

angular.module('App', [ 'ionic' ])
        .config(function ($stateProvider) {

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

That said, it's not about loading html within <ion-content> , but about navigating between states, and ionic and ui-router manipulate your HTML page automatically to effect navigation.

This is a SPA app (Simple Page App) and several HTML templates are loaded on the single page and are hidden or shown as you navigate between states.

    
25.11.2015 / 13:52