Let's build a mobile application with Ionic Framework #3

Today We 're gonna start to write some code , first is make a main controller to our ionic application
, of course by controller i mean angularjs controller .



we start by add ng-controller to our body tag , but this is just a reference to controller we need also

to create this controller (MainController) . 





The idea is just use http call to get the data.json

AngularJS comes with built in $http service  to make (GET,UPDATE,POST,DELETE) in our case

we are are doing get call

app.controller('MainController',function ($scope,$http) {
  // body...
  $http.get("data.json")
    .then(function(response) {
        console.log(response)
    });
})

we are just login data in the console.

NB : the http call could make some time before it returns the  data in , our case we are working localy, but in real life we have to work with web services and  probably internet connection like mine lol,
you guessed it, we need to use some techniques and tips for that, such as displaying  loader , error messages, .. fortunately Ionic integrated magic components .

in the next part we are going  to display this data as a ionic card and adding loading to our app

Comments

Post a Comment

Popular posts from this blog

Twitter API with PHP

Realtime Chat Application with CakePHP and Socket.IO #1