React.js vs Angular 4 overview

WRITTEN BY GARETH DUNNE @JSDIARIES

As I started this blog I had a bit of tunnel vision for wanting to focus on Angular and all its related technologies almost exclusively.

At that point my interest turned to Ionic as building hybrid applications using web technologies was extremely appealing to me.

And while I do think that specialisation is extremely important I also believe that loyalty to one technology can really limit opportunity and inhibit you from looking at the bigger picture.

I had averted my thoughts towards React.js for quite awhile, I really didn’t ever give it much consideration at all. The blog has died down in recent times as I’ve been working quite a lot with it and wanted to give a brief comparison to Angular.

Initially I’m going to give a non technical comparison but may follow up this post with a more in depth analysis.

If you are immediately looking for a learning resource for the React + Redux pattern have a look here.

I would also recommend having a look at Toptal covering the react ecosystem here as well.

Otherwise, this is a great starting series by thenewboston.

And in addition to this, a very clear and concise demonstration of React with Firebase was created by Wes Doyle.

React.js

Angular and React.js are compared constantly on many a forum, blog post or subreddit. But this comparison is only partly fair because while, yes, they are both hugely popular frontend tools, React.js is a library and Angular 4 is fully packaged framework.

React was originally created by Facebook in 2011 and was subsequently introduced into Facebook feed soon after. Come 2012, and it was implemented into Instagram too. It has come leaps and bounds since with a whole host of collaborations with other technologies etc.

Generally speaking React.js is quite lightweight due to it only being a library and like the latest in frontend frameworks, its aim is to provide an infrastructure that creates web applications with high speed reactive data and scaleability.

I personally think that React should be compared to Angular only when used in combination with Redux, a library that provides data state management for an application. This is when the benefits of React became more obvious to me. However, we will just go over a few aspects that both can be easily compared.

CLI

So this is where React and Angular differ in a more obvious way. Angular ships with a CLI (Command Line Interface) packaged with it. Again, this is due to Angular being a full framework rather than library like React.

Having said that Angular is very much a framework that relies heavily on CLI scaffolding for creating its project structure and directories. This also includes generating Ionic components too. You can really generate a wide range of file types for your project. This includes services, components (with or without scss enabled),  interfaces(for TypeScript), directives, pipes etc.

For more information check it out the CLI Docs here.

On the other hand,  React.js is less impressive in terms of its CLI capabilities out of the box and to be honest there isn’t any external package CLI that is as comprehensive as the Angular one.

However, a tool called create-react-app  exists which is an incredibly impressive piece of utility to have when starting your React.js app.

Its has every asset that you would require to build out a modern react project including ES6, Flow syntax and a great linter for catching common compile errors.

It really is an all encompassing package and reduces the downtime of starting a new application without the worry of all the setting up of many extras in this current era proclaimed as JavaScript Fatigue.

TypeScript

I originally started using TypeScript with Angular as it was built into the framework. However using TypeScript with React and Redux is just as incredibly enjoyable and effective.

In combination with Typescript, if you also include an ES linter in your coding environment you are really set up to write effective and clean code, as your code will not compile if something is unused or anything you write could possibly be null.

This is available for both React and Angular so theres not much advantage for either one here except that Angular comes packaged with TypeScript, while it may not be as obvious how to use it with React.js

However there is a fairly comprehensive blog post about it here that I encourage you to check out.

To create full React/Redux/TypeScript ecosystem can be quite challenging to get right. However, its a very well regarded to use this combination as it provides the developer with very well written code as well as incredibly power state management processes for managing your data in relation to your UI components.

This TypeScript-React-Starter template repo takes a lot of sting out of setting this powerful combination up.

Hybrid App Development

The potential for hybrid app development with both of these technologies could potentially be a tipping point for developers. Both offer very different approaches for this.

On the Angular side of things we have Ionic for producing web view based applications that can be published to both app stores. I have covered Ionic extensively on the blog before so please start here if your looking for more information.

In a nutshell, Ionic provides us with a very nice infrastructure to create apps that run in the web view on a mobile application. They tend to be not as fast as its native app technology counterparts

Meanwhile React Native has gained a lot of attention as of recently due to its fast and powerful production of natively functioning applications using JavaScript and React.js.

From what I have ready there is a lot of positivity for React Native going forward and its one to definitely watch out for over the next year.

I would also recommend that you check out how Airbnb is using React as this may further convince you of its potential.

 

In fairness, Angular also has native mobile app creation library called NativeScript . And while I don’t have personal experience with this the general consensus seems to be that is not as popular but just as capable.

A blog post by  goes into more detail about the comparison. And to be honest both both technologies are just capable as another for providing hybrid and native mobile development.

Documentation

There isn’t too much too compare here. Both of these technologies have informative documentation but in all honesty I would say the Angular docs are far more comprehensive and clear than the React ones.

This is just my opinion but the use cases and examples from the Angular docs stood out more to me.

Conclusion

So what can you take from this overview exactly? Well I really don’t think there is a clear winner from these comparisons alone. And really there won’t ever be a clear winner to most people, both these front end technologies are modern, fast, full of functionality and are just as capable as each other.

So your personal prefernce will go a long way in choosing what you find the most comfortable and suitable for your frontend aims.

But there is no doubt that Angular and React (and Vue!) will be here for years to come as they are changing the way user interfaces interact with data and styling.

As I get to gripes with a React, Redux and Typescript stack I find myself switching over somewhat. However, we’ll see how this goes but I will be providing some more technical posts of this stack in the future.

Common Ionic 3 Development Mistakes

WRITTEN BY GARETH DUNNE @JSDIARIES

As I have got to terms with many of Ionic’s development ways I have encountered a whole host of different errors that has slowed my development down.

In many ways, this is key to learning the framework, however I thought I’d share some of the more frustrating moments that I encountered so that a developer may be able to be more aware in his/her app building process.

I decided to create this post after seeing a simliar post from Toptals most common ionic development mistakes.

Again, if your looking to expand your Ionic knowledge I highly recommend this Ionic 2 cookbook.

These mistakes stem from an app that I made called CoffeeTrail.

Android Coffee Finder Application CoffeeTrail
CoffeeTrail

It’ll be on the iOS store very soon but be sure to check it out on Android here.

Cordova Documentation

The Ionic framework is built on top of Apache Cordova.
Cordova is responsible for packaging your HTML5 app as a native app that can run in Android, iOS, and other platforms. They have documentation that is both informative and verbose and should be read frequently when experiencing bugs and errors.

This seems to be relatively simple idea but one I was consistently ignoring at the start of my development. Whenever I would search for specific Ionic errors I would limit my search to all things Ionic, including the Ionic forums, stack overflow etc.

A lot of the time I would actually find a solution by looking at the Cordova documentation.

As Cordova is really the bread and butter of an Ionic application it can really help to examine information about specific plugins that power your application.

There is a significant amount of useful documentation here, especially for platform specific information for Android and iOS:


Ionic View

One of the handiest ways to produce an .ipa file without owning a Mac is to use Ionic Package. Ionic Package builds your application in its own cloud so that you can download it from their server.

However, you still have to run around many configuration steps to produce an .ipa file.

My advice here is to meticulously follow the Ionic Documentation to do this.

And any time you want to generate a Apple keychain file or p12 from a Windows machine have a look at this guide here.

Once finished you can view your application via the Ionic View app here.

This is very useful for testing your application across a wide range of device since you are testing it on a server just download the Ionic View app onto your desired device and test it out.

Configuration

Just because we are developing hybrid applications does not mean we don’t have to still specifically cater to each platform in some shape or form. I quickly found this out when using the Google Maps SDK.

When building with Android I had no problems and the map, locations and assets would be retrieved from the Google servers without an issue.

However when building for iOS the map would never display like so.

Ionic Google Maps Error
Ionic Google Maps Error
.

And after checking the network requests in the Safari there seemed to be no problems. With no errors logged after debugging and confirming that the map element is actually loaded I initially I thought this must be a style issue with the div map element but after some deliberation I found out in the Cordova documentation some extra information was needed in my config.xml file. specifically for iOS.

According to the docs , applications without any tags only have file requests from urls that are allowed.

Resources

When you are ready to build your application to production you will need to generate your image resources for your project.

We can do this using the command :

A lot of the time my original splash image wasn’t at the correct resolution to be transformed into various other dimensions for mobile tablet etc. Ensure that you can correct this as the resources step is required for building to iOS or Android.

For more information check out the resources in the Ionic Docs.

Serving your application

Whenever you use the command:

Your application is wrapped in a display for each platform. This is also the case if you use Google’s developer tools mobile responsive view, your application will render the components relevant to Android or iOS and even Windows.

While this is undoubtedly useful to preview platform specific components do not assume that the behavior here is representative of what will actually happen on an emulator or a real device.

This may seem obvious; however, I was initially confused by this as the -labs display resembles an authentic emulator. For actual emulators you can use Xcode for iOS or Android SDK Tools for Android applications.

So these are just a few of obstacles I encountered throughout my development time with Ionic. If you are looking for some valuable tutorials and resources, feel free to check out my previous post regarding excellent learning tutorials for Ionic.

Top Ionic Resources to Learn Hybrid App Development

WRITTEN BY GARETH DUNNE @JSDIARIES

Hybrid app development is an extremely fast growing niche. In particular, Ionic 3 is a platform that allows you to produce and distribute your app ideas to the market without having to specialise in iOS or Android development.

We can use the latest and greatest from frontend web technologies such as Angular 4 to power these apps. If you have previously read any of the Ionic content here, such as Creating a Google Map Place or Ionic 3 whats new? then none of this will be news to you. However, I wanted to list what I think is the highest quality learning content available now in relation to Ionic 3.

While there currently isn’t a proper Ionic 3 book to use as a learning resource. This Ionic 2 cookbook covers a wide range of Ionic developing basics and more.

Toptal also covers some common Ionic development mistakes here.

Content that is more practical than theoretical will always be a stronger learning asset so hopefully some of these will help to continue or start your Ionic development path.

Coursetro

Starting off with the Ionic related content on Coursetro.

I cant emphasis enough how much knowledge is gained from following any of Gary Simon’s Ionic related courses.

Starting all the way from designing a prototype in Adobe XD to implementing and developing your designed app using Ionic 3, no other content practically nails down the broader scope of full stack development by creating hybrid apps.

In particular, the course focusing on creating a gaming related app could not be more practical for creating a high quality application with solid functionality and purpose.

Just note that this tutorial in particular is behind a monthly subscription model, for one of the non premium app courses you can see the Wife Alert app which is not updated to Ionic 3 but the core fundamentals of Ionic are still there to learn.

Paul Halliday

Paul is one of the most prolific publishers when its comes to Ionic 3 content at the moment. He covers a plethora of useful Ionic 3 tutorial on his Youtube channel as well as some Udemy courses which I have no experiences with but if they are anything like his free content they are up to a very high standard of teaching.

I’m constantly learning new technologies that I can use in combination with the Ionic stack that would not know otherwise. On those terms, he is unmatched in the Ionic tutorial world.

Here are some of my favourites of his free content.

Joshua Morony

One of first Ionic tutorial publishers, Joshua provides frequent, useful and clear cut tutorials on his website and Youtube channel. There is an abundance of content that you can explore and he is up to date on the Ionic 3 front.

Joshua provides very good elements of clarity as he explains his content and has an impressive amount and experience publishing Ionic content.

Some great material here:

Raja Yogan

Raja has produced some very nice, lengthy and free content on Youtube. He provides very useful and fully fledged practical Ionic examples, usually in combination with Firebase.

I really enjoyed his latest chat application and encourage you to check it out, as its a fantastic series for building your own application using Firebase and Ionic. He is also a publisher who speaks clearly and teaches by example with no unnecessary theoretical fluff.

Exploring any of those publishers content is a great way to really get to grips with Ionic and Hybrid Web Development in general. All with their own different teaching styles, even spending a few hours will be more than beneficial to understanding various concepts for hybrid development.

Angular 4 News Roundup June

WRITTEN BY GARETH DUNNE @JSDIARIES

ng-June

June has come and gone and it has brought with it a steady month of Angular 4 news. There is a chance that you could have missed a change to key features or components so I’ve listed some of the main snippets of news that may have passed you by.

Although there isn’t much reading material specifically for Angular 4 I recommend having a look at ng-book: The Complete Guide to Angular 4 here.

Its updated with Angular 4 practices and is one of the few books doing so.

Angular 4.2

The most notable piece of Angular news this month is the release of Angular 4.2. This is a small update and will not break your current Angular projects via Semantic Versioning which I covered in a previous post here.

All changes pertaining to the release are mentioned on the official blog here. So what are main highlights we should take our of this update?
Well, the changes to allow the creation of reusable animations using the animation() function enables our animations to become more modular.

I’ve listed a very similar example as the docs here for reference.

As you can see we assign our animations to a variable, specify its animation properties and then invoke it using the useAnimation function

Typescript 2.4

Typescript has also updated to a new release, bringing with it dynamic import expressions as well as Safer callback parameter checking. There could be few posts written about these changes so I’ll let the official blog post do the talking here.

I’ll just note that the dynamic imports feature in particular is a fantastic addition in this new release. It allows an even deeper layer of lazy loading and enables Webpack to split your bundles even further to only load a particular asset required in a function.

Angular IO
angularIO
angularIO

In order to coincide with Angular 4 features and benefits, the official angular.io website has now been converted to a full scale web application. It is now much faster and has increased its performance significantly.

There is also a satisfying element of practice what you preach and the Angular team have clearly rebuilt the website from the ground up with performance in mind.

It may seems like a minor detail but searching through the documentation has now become a better user experience which I’m sure is appreciated throughout the Angular community especially for those browsing on mobile devices.

These were the main notable Angular events and features this month. The framework is progressively evolving every month and if theres enough newsworthy item in July I’ll be sure to do a similar roundup.

Still looking to upgrade your AngularJS app to Angular 2? Check out this tutorial by Toptal here.

Creating A Reactive Data Source in Angular 4 – Part 2

WRITTEN BY GARETH DUNNE @JSDIARIES

In this part of the tutorial we will be focusing on our API calls and how they interact with the brewery API.

Again, if your looking to expand your Angular and Typescript knowledge I highly recommend this Angular & TypeScript book by Yakov Fain.

You can see the final version of what my beer app is here. I took the designs and styles of this application from Coursetro’s MEAN stack course and was able to implement a service for interactions with the data and the Brewery API.

Proxy

First up, in order to get data from the Brewery API we want to enable CORS (Cross Origin Resource Sharing) in our browser.

To accomplish this we have two choices:

The easiest option here is to install a CORS Chrome extension here.

This will enable you to perform cross origin shares in Chrome without having to setup a local proxy. This is handy for testing an application locally but would obviously fall short if pushed to a production environment or hosted externally.

The second option, which is something I would encourage you to do is to setup a local proxy. This will allow you to easily enable cross origin resource sharing for all your browsers and doesn’t take long to create.

To do this lets first create a proxy.config.json file in the root of our project directory.

Proxy file location
Proxy file location

This is our proxy API json object. It contains properties that allows our calls to send and receive data to the Brewery API.

However, it won’t work without running the proxy file alongside our application. So we will need to execute this command to start it alongside our application.

Beer Model

Next we need to create a beer view model. This will basically act as an interface for our retrieved data. Properties such as name, description etc will feature here.

In your app folder create a file called beer.ts and put in the following.

We can now import our Beer class to any of our components to reference data retrieved from the Beer API. This is

Get Beers

We now want to implement a method that retrieves all beers from our Beers API. Open up beer.service.ts and change it to the following.

So we now have a getBeers() method and a handleError method for our beers API call.

In our if condition we first check if this.result variable already has a value. This is an important step because our service shares permanent data throughout our application so if the application has already been loaded then there is no point in making the getBeers API call again as the data is already cached in the our browser/service to be used.

We then take the _http variable of type HTTP that was created in our constructor and then invoke the get method using our beer API url details as the parameters for it.

The line .map((res: Response) => res.json()) takes the response from the Beer API server and maps it into an JSON array for us.

.publishReplay(1) will allow the data to be reactive. We will come back to this.

.refCount(1) has a similar function. It allows the Observable returned by the HTTP get request to keep its connection open, this will allow the data source to be reactive.

catch(this.handleError) this will catch any error from our request and run the this.handleError function. All you really need to know about this function is that it will filter down through the error message to the point where it will usually be the most informative. Usually, a detailed HTTP code error or associated.

If you noticed some of the variables declared above the constructor you should see

These are both core Rxjs features that will allows our data to be reactive. We will come back to these but for now just think of them as reactive variables that we will using later on in our home.component.ts

This is the basic version of our service set up with the functionality to retrieve an initial list of beers. It gives a good overview of how our service will share data. However, this on its own will not do anything without injecting it into one of your components.

We will be doing this in part 3. For now think of its as a piece of functionality that will share data throughout the application, the data will be made reactive by using Rxjs Subjects and Observables which are declared at the top of the file.

Creating A Reactive Data Source in Angular 4 – Part 1

WRITTEN BY GARETH DUNNE @JSDIARIES

One of the most important aspects to nail down in Angular 4 is the idea of creating reactive data sources. No matter what kind of data you want to show your user, in order to take advantage of web applications you should really have your data be dynamic and reactive.

In comparison to React.js, Angular 4 enables you to create data that is shareable to all of your components via a service . We will then use Observables and Subjects to make this data reactive. This is achieved using the external reactive JavaScript library Rxjs.

And while Rxjs is also available to be used with React, in my personal opinion it is much easier and it better fits the architecture to be used in combination with Angular 4.

In this tutorial I hope to show how you can make your own reactive data source using the Brewery API for data. In this part we will just start with setting up the project.

As per usual if your looking to expand your Angular and Typescript knowledge I highly recommend this Angular & TypeScript book by Yakov Fain.

You can see the final version of what end of this tutorial series here. I took the designs and styles of this application from Coursetro’s MEAN stack course and was able to implement a service for interactions with the data and the Brewery API.

Source

As this tutorial will be broken down into a few posts, you can see the source code in the GIT here.

Brewery API

In order to retrieve data from a source via HTTP we will use the Brewery API. This will at least keep our data source interesting and offer plenty of different data options to be displayed.

Navigate to the developer API section here.

Brwery API Menu
Brewery Applications

After signing up for a developer account, create a new application with whatever details you like.

Register New Application
Register New Application

The documentation is quite verbose and you can find a wide variety of different ways to query the api for specific beers.

You can also test the results of any api calls via the api explorer. This is useful for when you are testing different query parameters to retrieve specific datasets of beer information

API Explorer
API Explorer

For now, we just need the api key generated by your app. This will be needed in order to make a http request to the Brewery API server so store this somewhere to reference later on.

Setup

In order to progress from here we need to have Node.js and the Angular CLI installed.

No better way to get started than to watch this starting video by Gary Simon from Coursetro.

Once set up, we need to scaffold our Angular application. This is very easily done through the Angular CLI.

We will open up our terminal and in our current directory we want to generate the project with the styles scss flag.

We have now generated a Angular project with a sass styling structure.

Next lets generate our home component. This is a component that will display an initial request of beer from the API.

From here, we want to generate our service that will hold all the logic for retrieving data that can be shared with any of our components.

This is a service that contains all our methods that we will use to request data from the Brewery’s APIs. When you open up this service you will see that the Angular CLI has automatically injected a HTTP object into the constructor for us.

Lets modify this service so it now looks like this.

This HTTP object in the constructor will be used to make the HTTP requests. Meanwhile we have added all the necessary imports in the top of the file that we will need later on for this service.

This is our basic structure set up. In part 2 we will add our API calls to our beer service.

Ionic 3 – HTTP Requests – Retrieving a Photo from a Google Place

WRITTEN BY GARETH DUNNE @JSDIARIES

As I become more comfortable with Ionic 3 and its functionality, I wanted to share how to connect to the Google Maps API, retrieve a specific place and then to request a photo from that requested place.

In doing so, you will then know how define a HTTP object using TypeScript and using ES6 Promises in order to make a callback function that requests the photo using that HTTP object.

This functionality stems from an app that I made called CoffeeTrail.

Android Coffee Finder Application CoffeeTrail
CoffeeTrail

It’ll be on the iOS store very soon but be sure to check it out on Android here.

Setup Project

As always we can generate our Ionic 3 project using the command

We then want to generate our locations provider.

This is a provider that contains all our methods that we will use to request data from Google’s APIs. When you open up this locations provider you will see that the Ionic CLI has automatically injected a HTTP object into the constructor for us.

This is the object we will be using to make the requests.

We will also generate a location-details component that will display our requested images.

API Key

In order to have access to multiple API calls in our app we need to request a developer API key for Google Maps.

You can generate one by going to this page and clicking Get A Key , This is required for all place and photo requests and won’t work without one.

Google API Key
Google API Key

Get Place

We will create a getLocation method that will accept latitude and longitude as parameters.

We utilize a ES6 JavaScript Promise that will use the http object created in our constructor in order to make the request along with the details of the location which you can change for your own personal preferences.

You will of course have to reference the API key that you created earlier on in the apiKey variable of type string..

This Promise will return true or resolve when the the request has been completed and the data has been returned. The results of the data is mapped to a new json object which we assign to the this.data variable through ES6’s arrow functions .

This data will be resolved/returned when we call it in our location-details file.

We also can add the getPhoto method.

This will take in a photo reference string as a parameter in order to a retrieve a specific photo based on the location from the locations/location returned from our getLocation method.
So how do we get the photo reference from the data set returned from getLocation? Well we can do this in the locations-list file.

Display Photo

Our location-details.html file should look like this to display the retrieved image of the location.

Notice how we use the async pipe with the current image template variable.

This is because some asynchronous data objects can be a bit tricky to display without async pipe. The data source is an Observable that contains an array so using the async pipe secures it so to speak.

We then use the ng-template (which is new to Angular 4) syntax to display error text if no image can be retrieved.

So in our location.details.ts file we need to use our getLocation method in order to get a place and then to send a photo reference from that place to the getPhoto method.

This is just one way to retrieve data from an API in an Ionic application. The use of Angular 4 in an Ionic 3 project enables a developer to makes a request for some data and then to easily share that data throughout the rest of the components using a service or in this case, using our location.ts. provider.

Angular 4 News Roundup April

WRITTEN BY GARETH DUNNE @JSDIARIES

Whats New?

As more and more developers are upgrading their projects to Angular 4 the initial confusion of this sudden incremented version has settled and has brought with it some handy but hardly groundbreaking changes. I covered this in another post here.

Although there isn’t much reading material specifically for Angular 4 I still recommend having a look at Yakov Fain’s Angular and Typescript book here.

Angular Attack

Over a 48 hour period developers were instructed to create an Angular application to be submitted and reviewed with the best receiving a wide range of prizes. There are a lot of impressive entries and some really nice user interfaces were created in that short space of time.

Be sure to check out the entries here and the prizes here.

ngConf

Claimed to be one of the biggest and original Angular conferences. ngConf took place on the 5th to 7th of April in Salt Lake City Utah.

With plenty of Angular related content and speakers your bound to find something useful for you.

Plenty of topical and insightful information can be found from these talks so be sure to have a look at some of the speakers when you find the time.

Here are all the related live streams that took place over those 3 days. Use this schedule list here to find a talk that you want to listen to from the recorded live streams.

Animation

As covered in a previous Angular post, the way animations are imported has been simplified in Angular 4. One of the best videos to come out this month regarding this is Coursetro’s Angular 4 animations video by Gary Simon.

He presents his videos very well and concentrates on the broader scope of the full stack developer, starting from conceptual design all the way to full development in Angular. Be sure to check our more of his content, most of it is free,

Angular 5

Almost unthinkable at this stage right? Surely there can’t be anyone contemplating details of another Angular version? Well there actually has been a few hints from ngConf .

The release window is estimated for Autumn 2017. Not much details are revealed but promises of simpler and smoother Ahead of Time Compilations were hinted at. And although it might seem ridiculous to think about another version already, this is the path Angular will be following form now on.

Every forthcoming version will contain small and efficient refinements to the previous Angular version every 6 months or so. Not much core changes but rather notable improvements to make your development life smoother. We can only hope that not much is broken in the process with each of these incremental versions.

For more information please check it out this post here.

More Angular 4 and Ionic content will be sure to covered here so subscribe to the mailing list if you haven’t already.

As we grow, we hope to implement a job board that will have listings of some open Angular positions. Hopefully, this will connect potential employers with some of the developers from the JSdiaries community.

Still looking to upgrade your AngularJS app to Angular 2? Check out this tutorial by Toptal here.

Ionic 3 Release – Whats New?

WRITTEN BY GARETH DUNNE @JSDIARIES

Ionic 3 has released and with it, has brought some impressive but not overbearing changes to the Ionic framework.

While sites like Toptal have previously covered performance differences between Ionic 1 and 2.
This post will cover the upgrade from Ionic 2 to 3 and the performance differences that come with it.

Similar to the Angular 4 release, this isn’t a core change to the platform, rather it is adding some improvements to your applications that will increase overall performance and allows hybrid app development to come a few steps close to being on par with its native development counterparts.

As always here is some useful Ionic reading material. And here is the official post from the Ionic team specifying all the changes.

Updating from Ionic 2

Updating from Ionic 2 is actually quite a simple process. This video from Paul Halliday simplifies the process even further:

Angular 4

Ionic has been updated to be compatible with Angular 4 and all the features that come with it. You can find our Angular 4 release post here.

And the official Angular blog covers it here aswell.

Lazy Loading

One of the most notable features of the release, lazy loading provides us with the ability to breakdown our bundles for our application even further.

This allows our application to only load certain bundles/modules when they are actually needed. When you lazy load, your application performance improves, particular as the app is starting up because all the modules that were previously loaded in our app.module.ts are not requested at once rather they are loaded on a page by page basis.

I would highly recommend checking out Paul Hallidays tutorial on this:

TypeScript 2.1 and 2.2 compatibility

As specified on the official Ionic blog. Ionic 3 has been updated to be compatibly with Typescript versions 2.1 and 2.2. This is inline with **Angular 4 ** being compatible with these versions as well. More information can be found here.

A Promising future

So that just about summarizes the main changse for Ionic 3. I don’t think anyone can deny the momentum and progression that this framework has going for it.

While originally I was concentrating on all things Angular. Ionic has really provided such a sleek way to use web technologies in order to reach such a wider userbase and to target them more personally through mobile applications.

If you needed even more detail regarding Ionic 3 changes please check our Joshua Morony’s detailed guide here:

I highly recommend all his content as it provides a huge insight into all potential features you might want to implement into your application.

Angular 4 Directives Overview

WRITTEN BY GARETH DUNNE @JSDIARIES

If you missed our last Angular post please check it out here.

Not much has changed in terms of directives for Angular 4 so this post will be a general directive overview mentioning Angular 4 directive changes where appropriate.

Under the hood, a directive in Angular is just a plain JavaScript class that is decorated with the @directive decorator. In Angular, we have 3 different types of directives.

These are:

  • Component Directives
  • Structural Directives
  • Attribute Directives

An attribute directive tends to change the look and behaviour of an element. Whereas a structural directive will manipulate the DOM and add or remove elements depending on what action the structural directives apply.

A Component Directive uses the shadow DOM to create encapsulated visual behaviour that is typically used to create UI widgets.

Some directives go beyond the scope of this post but be sure to check out this awesome Angular book by Nathan Murray for additional information.

Attribute Directives

We will start with attribute directives and how this interacts with our DOM and data.

We can also differentiate a component from a directive using this handy table provided for here.

You can create your own attribute directives or you can use Angular’s built in directives.

https://angular.io/docs/ts/latest/guide/attribute-directives.html

ngClass

A fairly simple illustration of a basic attribute directive, ngClass is added into our component element and its value is given as a class.

As you can see, we can use the ngClass attribute to assign a class based on styles that we had specified in our styles array.

ngFor

In short, ngFor is a directive that outputs an array element, iterating through each element inside it.

For multiple classes, we can create an array and put those classes inside it to apply to our iterative list. We can then combine this with the aforementioned *ngFor.

The let key is part of the Angular template syntax. It creates a local variable that can be referenced anywhere in that specific template. let also creates the index i and keeps it as a reference to the current whiskey. All this is done under the hood of this directive.

What if we wanted to style the first and last item in our ngFor directive? This is actually made relatively easy by using let again to assign the first items to variable first and last to variable last.

To be as efficient as possible, ngFor will attempt to not remove and recreate these DOM elements and instead to reuse and recycle when possible. This helps with performance and prevents significant slowdown in our DOM.

ngSwitch

ngSwitch provides us with a structural directive similar to a switch loops in JavaScript and our other Object Oriented language counterparts.

Here is a simple example that combines input button events with ourSwitchCase loop. Based on the number that value returns which is changed depending on which button is clicked, one of the divs with the *ngSwitchCase will be displayed.

NgIf adds or removes an element or elements from a sub tree based on the condition specified.

If the expression assigned to ngIf evaluates to a falsy value then the element is removed from the DOM, otherwise a clone of the element is reinserted into the DOM.

This would be similar to how the display: none property behaves in CSS.

The NgModel directive allows us to provide two way data binding to our HTML element. Whatever we type in the input field will reflect in our name element. In our sample Plunker we had to import and declare our FormsModule in order for this to work. The name attribute should also have the same value as our ngModel.

Creating our own Attribute Directive

I will be going over the fantastic introduction to creating our own directives from Angular University.

We can also create our own custom directives in Angular. In this case, this directive can be applied to any HTML element on the page and will hide this element when it is clicked.

Firstly, we need to import our Angular Directives from Angular core library into your component file.

We then need to then initialise our directive meta data decorator with the selector property of our choice. In this example its HideElement.

We then want specify the CSS classes that we want to use for the fade out transition.

And we also need an action to occur when the element is clicked so we will create a function called toggle.

We than want to use a click event that will trigger the function “Toggle” that will add or remove this fade out css class but we will not be using Angular’s (click) event so how exactly will we accomplish this?

Well, we will use the Angular directive HostListener from Angular Core. Using a Host Listener, Angular will invoke the decorated method (in this case toggle) when the our html element emits the event (when clicked).

In order to access and change properties of the Host Element we must use the HostBinding Decorator. This will check the host binding properties once a change is detected.

For a more detailed explanation of creating your own Angular directives check out this tutorial from Rangle.

If this helped you out be sure to check out our resources page for more recommended reading material on Angular.