Monday, January 11, 2016

Ionic


Installation on windows is possible, but takes time.  You can use c9.io to dev-test it (although the cordova part can't be used). Use:
npm install -g cordova ionic
ionic start myApp tabs (to create sample app)
ionic serve $PORT --nolivereload   (to shed few seconds on reload stuck)

Good tutorials are hard to find, and when I say good, I mean that the ratio of explanations rows to code rows is bigger than 1.
TODO: maybe this one: http://www.htmlxprs.com/post/6/creating-a-realtime-image-sharing-app-with-ionic-and-socketio-tutorial

States and Routing between pages

Let`s talk about the ionic starter tab apps (ionic start myApp tabs)
It uses state notion, which actually comes down to three built-in parameters behind the scenes:
$state = contacts.detail
$stateParams = {"chat.id":"1"}
state full url = /tab/chats/1

so if you have a list of people to chat with, and clicking on a person from the list will switch you to the chat-details, you will put a href="#/tab/chats/{{chat.id}}" on the item.
The state will know to search for the /tabs/chars/X , in our case this url is tab.chat-details


see this link to see how they change in realtime.
from app.js:
.state('tab.chat-detail', {    --> $state . it`s just the name, using X.Y let you inherit from abstract X 
      url: '/chats/:chatId',
      views: {
        'tab-chats': {
          templateUrl: 'templates/chat-detail.html',
          controller: 'ChatDetailCtrl'
        }
      }
    })
In the controllers.js , this how the controller asks for the id of the person:
.controller('ChatDetailCtrl', function($scope, $stateParams, Chats) {
  $scope.chat = Chats.get($stateParams.chatId);
})


Template for List

see: http://ionicframework.com/docs/api/directive/ionList




No comments: