Tuesday, January 6, 2015

Angular.js style guide: using an activate() method inside your controller

There are lots of opinions about how to write good Angular code. One of the best style guides out there is the one created by John Papa available at https://github.com/johnpapa/angularjs-styleguide.

It contains a large list of great tips about naming guidelines, application structure, testing, exception handling, and so on…

One advice that I started to implement recently is the usage of ‘Controller Activation Promises’. It solves the problem where you have your start-up logic scattered around across the controller. It places all start-up logic in a consistent place.

How do you this? Simple, create an activate() function and put all your start-up logic inside:

14 comments:

Gezerk said...

Thanks very much for the introduction to the Angular style guide. I have been using Angular and I was not at all happy with how I was doing it. The style guide was exatcly the guidance I needed it. I would never have found it without your post!

Raju Kumar said...

I am extremely impressed with your writing skills and also with the layout on your blog
Angularjs Training In Hyderabad

Aishu said...

Very good explanation.

AngularJs Training
AngularJs Training in Chennai

osvaldo anderson said...

AngularJS is an open-source JavaScript framework that assists with running SPA.
AngularJS Training

for IT the said...

Angular 2 Training in Chennai angular2 Training in Chennai | angular2 Training in Chennai


Angular 2 Training in Chennai AngularJS Training in Chennai AngularJS Training in Chennai Angularjs Training Angularjs Training AngularJS Training in Chennai AngularJS Training in Chennai

Adlearning Technologies said...

Thank You for sharing your article. I like it. We provide TIBCO Online Training in Hyderabad.

Philip Nielsen said...

Is this different from $onInit for Angular 1.5?

vinayangadi said...
This comment has been removed by a blog administrator.
InduPriya said...

Really Nice blog about AngularJS. Thank You.....

Rakesh said...

nice information
SoftwareTraining

Gopi Krishna said...

AngularJS is a toolset for building the framework most suited to your application development. It is fully extensible and works well with other libraries. Every feature can be modified or replaced to suit your unique development workflow and feature needs. Read on to find out how.

AngularJS Training in Chennai
AngularJS Training Institute in Chennai

AngularJS Certification Training in Chennai

Sujit kUmar said...

nice post for sharing angularjs article. its really helpful for me.keep sharing on updated angularjs tutorials????????????????

Thank you

Anonymous said...

On line 13 is the code:

return vm.avengers;

I am struggling to understand --- who is this being returned to, and why?

Hope you can help

Thanks
Brian

Albert Smith said...

Wow, although I landed on this page accidentally while I was looking for reference materials for Thesis Finishing, I have learned a lot about the art of simplicity and I am going to implement the outlined guidelines. Thanks a lot for sharing this blog post with us. I have found it to be very useful.