Angular Best Practices

Source :   http://trochette.github.io/Angular-Design-Patterns-Best-Practices

Tip #1: Keep your code organized

As developers we often struggle with code organization when scaling an application.
It gets messy and we start losing times searching for files.

Tip #2: Keep controllers simple

Controllers are meant to define your scope variables and encapsulate view related logic. Please don’t use controllers for DOM interactions or data manipulation.

Tip #3: Business logic belongs to models.

Data processing should always be kept in models, that way they can easily be shared between controllers and other services. Plus it’s easier to write unit test for them.

Tip #4 : Create facade to interact with servers

Keep it simple, separate server interaction and error handling from the model.
That way model only handle data processing and code is easier to maintain

Tip #5: Leverage provider configuration

Angular gives developers the ability to configure providers before they are injected inside other objects in our application. Use that to your advantage and handle global events like service errors from that level.

Tip #6: Share a Notifications Service

While it’s a good solution to bridge gaps between directives, controllers and models we encourage you to use $scope.$emit() and $scope.$broadcast when possible.
Don’t overuse it.

Tip #7: Automate your workflow

AngularJS ecosystem is growing fast. Each month new tools are released.
Use them to build your own boilerplate and use that for your projects

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s