Techies India Inc.
Banner

Things you must know before starting with angularJS

 

[fvplayer src=”http://techiesindiainc.com/wp-content/uploads/2015/06/Baldeep_Kaur_.JSFrameworks.mp4″ width=”500″ height=”500″]

In the recent past i got to work on a project using AngularJS. When i started working on this project i knew a very little about it. I had to go through lots of refactor and rewrite.. Believe me it was not a smooth ride. I wished if someone would have told me about the things i needed to learn before starting AngularJs. Are you wishing for the same? Don’t worry i am going to tell you everything that you need to know before starting AngularJS.

As a beginner, you need to know pretty much everything before starting. And after you have nailed it, there is pretty much nothing other than some common building blocks and best practices.

Lets start with the Intro first:

AngularJS is a javascript framework based on MVW (Model view Whatever) structure powered by Google to create modern interactive UI Web Apps. Although, it is a general purpose framework, but it truly shines when used with CRUD type applications.

The Learning Curve:

Angular.js has a very different architecture. It is certainly not necessarily important to learn all core concepts like module, service, dependency injection, scope. Knowledge of controller, some directives and the documentation is good enough for a quick start. Problem begins when you start digging deeper to write some serious code. Suddenly you start feeling like the learning curve has gone very steep. The knowledge and the documentation you have gained in the initial phase has apparently become incomplete.

A better understanding of modules is must before you start:

AngularJS doesn’t restrict you to use its modules for code organization. You may have a huge javascript file with lots of controllers in it. Every time your HTML is loaded, the same large javascript file is loaded along with it even if there’s only one controller in your file. Things can really get out of control due to this.

The best approach is to split controllers into various modules for different pages and extract some common filters and services from it. Make sure that all the modules has it’s dependencies set up right and components are correctly injected. Dependency injection (DI), often used in Java makes the code less coupled and easier to maintain.

What to do when your controllers become bigger?

On a certain phase you will find your controllers get bigger and bigger. In such situation you don’t need to be panic. You just need to break the controllers into sub controllers. This is pretty much similar with $scope. But before doing it you must need to know how $scope works. After learning how $scope works you can easily break your bigger controllers into sub controllers.

Do write directives while using DOM in controller

DOM and controllers are meant to be separate in AngularJS. But sometimes you might need to use DOM in controllers. This is the best time to use directives. You might have used directives but would have never thought to write it. Am I right? Let me tell you that directives are very important concept in AngularJS. It is not only a reusable component in JQueries but also into your various sub controllers to be used on various places.

Another problem you are going to face is the documentation of the directives in AngularJS. The documentation is very poor as there are very less examples and lots of abstract explanations. So how are you going to do it? Well don’t worry. The best way of learning something is, to do it. Even i used to stick on many points, Whenever I stuck anywhere I used to go back to documentation or search it around. and believe me, every time i stuck i come back with a better solution. So keep on exploring.

AngularJS Router – Not up to the expectation

Router in AngularJS has very specific usage. Unlike other frameworks it doesn’t monitor the location.hash. In such frameworks router monitors the location.hash and calls a function when the route matches. It acts as server side router in AngularJS and designed to work with mg-view. So you should better get ready with the solution if you don’t like this behaviour.

So these are the key points you must be considering before starting AngularJS. Remember, you never become perfect. Learning will always be there and there will always be some scope of improvement. Although I have been using Angular.js a lot in the recent past but i still cannot call myself an expert. Even this blog of mine has been written with the sole purpose of learning. So keep learning!



We'd love to hear from you

 
captcha