Learning the Ionic 1.x Framework as a Sencha Touch Developer: Part 2

Learning the Ionic 1.x Framework as a Sencha Touch Developer: Part 2

Follow Josh Morony on

In the last post we [installed Ionic and generated our first application][1]. We also looked at creating an [ionic.io][2] account and uploading the application to it (with that done you can test your applications on your device right away by downloading the [Ionic View][3] app).

Now we need to learn how to start using Ionic. As always, the best place to start is the [documentation][4]. Ionic’s documentation is especially user friendly, and you can see at a glance all the different topics you should be focusing on.

If you first head to the [Overview][5] page you will see a lot of the stuff we have already done mentioned. There is also some additional information mentioned though, specifically that:

  • Ionic supports SASS
  • Ionic comes with an [icon pack][6]
  • Ionic uses the MIT license, meaning you can use it in personal or commercial projects for free

Next, head to the [Ionic Book][7] section of the documentation. You can skip straight to Chapter 3 – Starting your app if you’d like but it may be worth while to have a read of Chapter 1 – What is Ionic as well. If you don’t end up reading the first Chapter, here’s a few important quotes I’ve pulled from there:

Ionic is an HTML5 mobile app development framework targeted at building hybrid mobile apps
Think of Ionic as the front-end UI framework that handles all of the look and feel and UI interactions your app needs in order to be compelling.
Since Ionic is an HTML5 framework, it needs a native wrapper like Cordova or PhoneGap in order to run as a native app. We strongly recommend using Cordova proper for your apps, and Ionic tools will use Cordova underneath.
Ionic also uses AngularJS for a lot of the core functionality of the framework. While you can still use Ionic with just the CSS portion, we recommend investing in Angular as it's one of the best ways to build browser-based applications today.

If you’re reading this as a Sencha Touch developer then all this should sound pretty much the same to you (aside from the Angular bit of course). If this is your first experience with a HTML5 mobile framework then perhaps [a little more background][8] will help.

[Chapter 3][9] walks you through building your first application with Ionic, a simple to do list app. The to do list and note taking applications are about as common as “Hello world!” apps for getting started – they’re a bit dull but are a good place to start learning. There’s no point in me duplicating the tutorial here so make sure you head over to the Ionic website to [complete the tutorial][9].

Remember, you will need to create a new blank Ionic App first by running:

ionic start todo blank```

As you start coding the application, the first big difference you may notice when comparing it to Sencha Touch is that HTML is used to define the structure of the application. Although HTML _is_ used in Sencha Touch to define templates, most of the work is done purely in JavaScript. For example in Ionic, we define a container with a list like this:



Whilst in Sencha Touch we would do this:

    xtype: 'container',
    items: {
        xtype: 'list',
        tpl: '{title}',
        store: "TaskStore"

I'm not sure whether I prefer this approach or not yet, I feel like Sencha Touch provides a cleaner and more manageable approach but it is easier to see what is going on at a glance with the Ionic approach.

I also found the way data is handled and submitted quiet interesting. Take a look at this sample code:

``` Although it seems a little confusing at first, this code will take all the input from within this form (or more specifically, anything defined on 'task') and submit it to the 'createTask' function. We then create the corresponding method in the controller: ```javascript $scope.createTask = function(task) { $scope.tasks.push({ title: task.title }); }; ``` This isn't all that different to the way Sencha Touch handles a form submission. In Sencha Touch we define our forms in Javascript, fire an event when the form is submitted and then [listen for that event in the controller][10] to capture the data. Again, I feel like Sencha Touch's way is cleaner, but the Ionic approach strikes me as being much easier to understand initially. _(I should point out though that it makes sense that I would find learning Ionic easier since I'm already familiar with HTML5 mobile frameworks, and I wasn't when I started with Sencha Touch. The overall process is pretty much the same between the two, there's just different ways of doing it.)_ The final noteable difference is the concept of a **Factory** in Angular, which seems to fulfill a similar role as the Sencha Touch **Stores**, which handle saving data to, and loading data from, local storage. Here's what I ended up with after completing the tutorial: Todo List App **UPDATE:** [Part 3][11] of this series is out now, and it's a big one! [1]: http://www.joshmorony.com/learning-the-ionic-framework-as-a-sencha-touch-developer-part-1/ "Learning the Ionic Framework as a Sencha Touch Developer: Part 1" [2]: http://ionic.io/ [3]: https://itunes.apple.com/us/app/ionic-view/id849930087?mt=8 [4]: http://ionicframework.com/docs/ [5]: http://ionicframework.com/docs/overview/ [6]: http://ionicons.com/ [7]: http://ionicframework.com/docs/guide/ [8]: http://www.joshmorony.com/should-you-be-learning-a-html5-mobile-application-framework/ "Should You Be Learning a HTML5 Mobile Application Framework?" [9]: http://ionicframework.com/docs/guide/starting.html [10]: http://www.joshmorony.com/how-to-listen-to-events-with-controllers-in-sencha-touch/ "How to Listen to Events with Controllers in Sencha Touch" [11]: http://www.joshmorony.com/learning-the-ionic-framework-as-a-sencha-touch-developer-part-3/
Check out my latest videos: