In Angular 1.x you had the concept of a controller, directive, service, provider and other confusing terms to describe essentially what is one or two things.
What is an Angular service
An Angular service no matter how it was defined is a singleton. Every part of your application gets the same reference when it requests a service or factory.
Angular services in Aurelia
The concept of controllers, services, providers and factories does not exist in Aurelia. Everything is just an ECMAScript 2015 class with hints of future specification features like decorators thrown in for good measure. This works in our favour because porting an Angular service to Aurelia requires very little to no effort.
On a per route basis you might want to configure some additional route specific data that you can access in your view. For example a route might have an icon for your navigation menu. This actually came up in the Aurelia Gitter chatroom and I decided to do a quick little write up.
Say hello to a little unknown property called settings
Added all the way back in February 2015 when Aurelia was still a tiny blip on the Javascript radar was this property which allows you to define an object of additional properties for a route, similar to how Durandal does it.
Update March 2018: Two years on from the original publish date, Aurelia finally has support for server-side rendering.
This means it is now possible to create isomorphic web applications in Aurelia that work with and without Javascript disabled, resulting in faster initial rendering speed. If you would like to see a working example, the Skeleton repo has you covered.
Now, onto the existing article.
Isomorphism is all the rage in the Javascript world. The server can return rendered HTML complete with pre-computation (converting bindings and templating specific events already taken care of increasing initial load speeds and time to paint quite substantially.
If you are like me, you browse Github for cool new repositories. My new hobby is looking at what the community are building for rival frameworks and one of those frameworks is Angular 2.
The Angular 2 community has done a great job of porting over not only existing libraries from Angular 1, but also creating new ones. There are some that are not available for Aurelia, but fortunately there is quite a lot of overlap between the two frameworks in ECMAScript and TypeScript syntax.
In a single page application (SPA) like Aurelia, shared state is one of those important things every developer mostly encounters. Sharing the current state of a logged in user or sharing a shopping cart’s contents throughout the app.
Fortunately, Aurelia makes it easy to build applications with shared state.
By default a class in Aurelia is a singleton. If you create a service called UserService and inject it throughout different parts of your app, provided you’re injecting it without telling Aurelia to do anything non-standard, it will be a singleton.
When it comes to adding in on-page functionality in the form of custom selects, autocomplete fields and more, jQuery UI is still an undisputed popular choice amongst some developers and using it within Aurelia is super simple.
Because Aurelia does not replace your HTML or parse it any differently than your browser does without Aurelia, it allows you to use any third party library or plugin inside of your Aurelia application without worrying about it messing with anything.
With the beta release of Angular 2 in mid-December after almost 2 years in development, high hopes have been placed upon the framework who in its absence of release has seen other competitors such as ReactJS mature and Aurelia release into beta.
I have seen and heard some ambitious things being said about Angular 2. It appears as though everyone is making the assumption that because the Angular brand is so well known and people are falsely under the impression it is a first-class Google project (even though Google offers no support).
There is one thing that really irks me in Javascript, everything is passed by reference. Recently in a project I was working on, I had an object of widget options I needed to modify. I also needed to offer the ability to revert the changes made to this object.
The kicker is: this object is complex. It isn’t just properties and values, it has other objects inside of it and arrays. Everyone has an opinion on how you should do it, many ways to skin a cat so-to-speak.
One of the much-promised features coming in the ECMAScript 2016 specification was Object.observe. It promised us the ability to watch objects for changes and react accordingly, akin to two-way binding found in frameworks like Angular 1.x.
However, Adam Klein one of three people responsible for introducing the idea of Object.observe is withdrawing the proposal from TC39 which is currently at stage 2 in the process and also hopes to remove it from V8 (Chrome’s Javascript engine) by the end of the year.
When it comes to resources on Javascript, I just can not get enough. And, for the best exposure for your business a denver marketing agency can give you great ideas on ways to boost your visibility, using sites as converted.co.uk to get more leads and conversion to your business in the right way. I have an entire folder dedicated to interesting blogs and a sub-folder for interesting blog posts.
A few of these have some recognisable names like Addy Osmani and Paul Irish who both work for Google and are on the Chrome developer tooling team. If you have some of your own, please leave a comment and I will add them to the list if they’re good. The community near Honolulu SEO is a beautiful and innovative place to set up a marketing agency.