AdrienF
AdrienF

Reputation: 978

ion-view doesn't appear inside ion-nav-view

After having done a few tutorials, I'm getting started with my own Ionic app. I got start with ionic's blank template. My problem is that my ion-view (in cards.js, see below) doesn't show up at all inside the ion-nav-view, i.e. I don't get any child HTML tag to ion-nav-view.

I used Adam's answer to this question to make sure my routes are correctly setup, and I don't get any error, so I think they are. I'm not trying to have tabs, just one view.

If I place a breakpoint inside my controller function, the execution isn't paused so apparently that code is not executed at all, but I have trouble going deeper into the guts of the framework to figure out what's going on.

Do you have any idea what I'm missing/doing wrong here ?

My code is:

index.html

<!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>

    <!-- libs-->
    <script src="lib/ionic-contrib-tinder-cards/ionic.tdcards.js"></script>
    <script src="lib/collide/collide.js"></script>

    <!-- your app's js -->
    <script src="app/app.js"></script>
    <script src="app/controllers/cards.js"></script>
  </head>
  <body ng-app="myApp">
    <ion-nav-view></ion-nav-view>
  </body>
</html>

app.js

angular.module('myApp', ['ionic'])

  .run(function($ionicPlatform, $rootScope) {
    $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('cards', {
        url: '/cards',
        views: {
          'cards': {
            templateUrl: 'app/views/cards.html',
            controller: 'Cards'
          }
        }
      });
    $urlRouterProvider.otherwise('/cards');
  });

cards.js

angular.module('myApp')
  .controller('Cards', function($scope) {
    $scope.cards =  [
      {title: 'Card-1'},
      {title: 'Card-2'},
      {title: 'Card-3'}
    ];
  });

cards.html

<ion-view view-title="cards">
  <ion-content ng-controller="Cards">
    <h1> Cards view </h1>
    <ion-list>
      <ion-item ng-repeat="cards in cards">
        {{card.title}}
      </ion-item>
    </ion-list>
  </ion-content>
</ion-view>

Upvotes: 1

Views: 1936

Answers (2)

aorfevre
aorfevre

Reputation: 5064

I have deleted previous post, as you pointed out that my reply was totally wrong.

Concerning your routing , here is mine. Do you see any difference with that synthax?

$urlRouterProvider.otherwise('/');

$stateProvider.state('camera',{
    url:"/camera",
    cache: false,
    controller:"CameraCtrl",
    templateUrl:'app/views/loading/index.html'
})

Upvotes: 2

Sharn White
Sharn White

Reputation: 624

I think you're meant to use one or the other. ion-nav-view is just an ion-view with slightly different behaviour.

So putting an ion-view within an ion-nav-view would be similar to putting an ion-view within an ion-view, which won't display correctly.

From docs: "and remember to replace ui-view with ion-nav-view in examples"

Reference:

http://ionicframework.com/docs/api/directive/ionNavView/

Upvotes: 0

Related Questions