Todo app - no items displayed? How to debug?


#1

Hi,

Been following the basic ionic todo app and for some reason I can’t get the items displayed when defined in the controller. What I get is a blank screen with no items.

However if I do not have this:

> <ion-side-menu-content>
>   <ion-header-bar class="bar-dark">
>     <h1 class="title">Todo</h1>
>   </ion-header-bar>
>   <ion-content>
>     <!-- our list and list items -->
>     <ion-list>
>       <ion-item ng-repeat="task in activeProject.tasks">
>         {{task.title}}
>       </ion-item>
>     </ion-list>
>   </ion-content>
> </ion-side-menu-content>

And replace it with this:

>   <ion-content>
>     <!-- our list and list items -->
>     <ion-list>
>       <ion-item>
>         Test
>       </ion-item>
>        <ion-item>
>         Test
>       </ion-item>
>        <ion-item>
>         Test
>       </ion-item>
>     </ion-list>
>   </ion-content>

I get “Test” listed three times as expected. Its as if the $scope.tasks isn’t found/not looped through but i’m not sure how to test this out.

I have two questions:

1. how can I try and access the variable declared $scope.tasks in the developer console to spit it out to see if it’s declared?
2. Any ideas what’s going on?

Full code:

app.js

angular.module('todo', ['ionic'])
.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if(window.cordova && window.cordova.plugins.Keyboard) {
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      // for form inputs)
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      // Don't remove this line unless you know what you are doing. It stops the viewport
      // from snapping when text inputs are focused. Ionic handles this internally for
      // a much nicer keyboard experience.
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})
.controller('TodoCtrl', function($scope) {
  $scope.tasks = [
    { title: 'Collect coins' },
    { title: 'Eat mushrooms' },
    { title: 'Get high enough to grab the flag' },
    { title: 'Find the Princess' }
  ];
});

index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Todo</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <script src="lib/ionic/js/ionic.bundle.js"></script>
    <!-- Needed for Cordova/PhoneGap (will be a 404 during development) -->
    <script src="cordova.js"></script>
        <script src="js/app.js"></script>
  </head>
<body ng-app="todo" ng-controller="TodoCtrl">
  <ion-side-menus>
    <!-- Center content -->
<ion-side-menu-content>
  <ion-header-bar class="bar-dark">
    <h1 class="title">Todo</h1>
  </ion-header-bar>
  <ion-content>
    <!-- our list and list items -->
    <ion-list>
      <ion-item ng-repeat="task in activeProject.tasks">
        {{task.title}}
      </ion-item>
    </ion-list>
  </ion-content>
</ion-side-menu-content>
    <!-- Left menu -->
    <ion-side-menu side="left">
      <ion-header-bar class="bar-dark">
        <h1 class="title">Projects</h1>
      </ion-header-bar>
    </ion-side-menu>
  </ion-side-menus>
</body>
</html>

#2

Dang, a few minutes after typing this I found the issue. Solved by changing

  <ion-item ng-repeat="task in activeProject.tasks">

to

  <ion-item ng-repeat="task in tasks">

So my question is just: how would I be able to print out $scope.tasks in the developer console (access it directly?)