Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

ionic Creating an APP

ionic Creating an APP

In the previous chapter we learned how to import the ionic framework into a project.

Next we will introduce how to create an ionic APP application.

Creating an ionic APP uses HTML, CSS, and Javascript to build, so we can create a www directory and create an index.html file in it, with the following code:







  

    

    Todo

    



    



    



    

    

  

  

  



In the above code, we imported the Ionic CSS file, the Ionic JS file, and the Ionic AngularJS extension ionic.bundle.js (ionic.bundle.js).

The ionic.bundle.js file already contains the Ionic core JS, AngularJS, and the Ionic AngularJS extension; if you need to import other Angular modules, you can call them from the lib/js/angular directory.

cordova.js is generated when creating an app with Cordova/PhoneGap and does not need to be imported manually; you can find this file in Cordova/PhoneGap projects, so showing a 404 during development is normal.


Creating an APP

Next we will implement an app with a title, sidebar, list, etc.; the design is as follows:

Creating a Sidebar

The sidebar is created using the ion-side-menus controller.

Edit the index.html file we created earlier and modify the content inside , as follows:





  

    

    

    

    

  



Controller analysis:

Initializing the APP

Next we create a new AngularJS module and initialize it; the code is in www/js/app.js:



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

Then add the ng-app attribute to our body tag:





In the index.html file's import the app.js file above:





Modify the content of the body tag in the index.html file, with the following code:





  



    

    

      

        

Todo

Projects

Try it »

With the above steps we have completed the basic ionic APP application.


Creating a list

First create a controller TodoCtrl:





In the app.js file, use a controller to define the list data:



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



.controller('TodoCtrl', function($scope) {

  $scope.tasks = [

    { title: 'Runoob Tutorial' },

    { title: 'www.runoob.com' },

    { title: 'Runoob Tutorial' },

    { title: 'www.runoob.com' }

  ];

});

In the index.html page we use Angular ng-repeat to iterate over the data list:







  

    

Todo

{{task.title}}

The modified code inside the index.html body tag is as follows:



 

    



    

    

      

        

Todo

{{task.title}}

Projects

Try it »


Creating an Add Page

Modify index.html at add the following code after :





In the above code we use