Using Ionic 2 with the Angular CLI

The easiest way to create and work on an Ionic project is to use the Ionic CLI.

However Ionic 2 is based on Angular 2, so we could say that an Ionic project is basically an Angular project with the Ionic framework added to it. You don’t have to use the Ionic CLI.

Ionic “the framework” is one thing, and the Ionic CLI is another thing. This is an important distinction that people just starting with Ionic frequently seem to miss.

Continue reading

Introduction to Angular 2 in JavaScript/ES5 – Part 1

This is the first of a new mini-series of videos on Angular 2 using ES5 i.e. the “classic” JavaScript syntax.

In this first part we see how to write a first Angular 2 Component, and introduce the concepts of Template, Metadata, HTML Plus, and the bootstrap method.

You can download the starting project mentioned in the video here: hello-world-0.zip

Interested in my upcoming full course on Angular 2? Pre-register here.

Angular 2 in ES6 without decorators

With Angular 2 now in beta, it’s definitely time to start playing with it. One of my first questions was: what language to use? The first example in the Angular 2 website says

While this example uses TypeScript, Angular works equally well with ES5, ES6 and Dart as well.

Those are the languages officially supported by Angular 2. Dart has lost most of its appeal since they declared it won’t be integrated into Chrome, so I’ll just gloss over it.

Angular 2 itself is written in TypeScript, and so are most of the official examples available so far. I do like TypeScript and it is arguably the best choice for large projects. However it may be overkill for smaller apps or just some quick experiments. Configuring type definitions for existing JavaScript libraries in particular can be a bit of a pain.

ES5 is just… old. If we use JavaScript for a new project today we may as well start with ES6. Surprisingly though I could find very few Angular 2 examples in ES6. And those few typically use decorators, a language feature that is not actually in the ES6 standard but one proposed for ES7. As a result it’s only partially supported by Babel for example.

So, is it actually possible to write Angular 2 components in “pure” ES6, with code similar to the TypeScript examples but without types and decorators?
Continue reading

How to use JavaScript 2015 (ES6) now in your Ionic app

ECMAScript 2015 has finally been approved a few days ago. The new JavaScript standard – also known as ES6 – introduces a wealth of new features, from arrow functions and classes to block-scoped variables and modules, and many more.

JavaScript 2015 is a much richer, more modern language that tackles many of the shortcomings of earlier versions and is a lot more fun to work with. Shame that we now need to wait some time before all the major browsers will support the new standard… Or do we?

Well, thankfully we don’t. We can use ES6 right now. There are a few transpilers that can take ES6 code and translate it into ES5 code that happily runs on existing browsers. In this post, I’ll show you how to configure an Ionic project to use the Babel compiler.

Continue reading