Top 5 Common Angular JS Mistakes Web Developers are Making

AngularJS is one of the most invincible and profound Javascript frameworks launched by Google in 2009. The main function of this framework is to illuminate the web development life cycle that makes it immaculate for prototyping smaller applications.


Thanks to its flexible and secure structure, it quickly became a popular choice among many web developers. It has been used to develop Single Page Applications that can render amazing User Experience and User Interface. In simpler words, it builds scalable applications that can be used on a variety of devices.


Though AngularJS is an extraordinary JavaScript framework that provides multiple features, it certainly has created many challenges and pitfalls for the developers while creating dynamic web applications. In order to leverage AngularJS, there are few mistakes you need to avoid that you are probably making.


Here is the list of top 5 most common AngularJS mistakes:


1. MVC Directory Structure

AngularJS is an MVC framework that offers MVC components to build web applications. The components are not evidently defined as a framework such as Backbone.js, but the architectural pattern still perfectly fits.


The best way to work with MVC framework is to group files together depending on their file type.


As an instance:






















Seems familiar? Well, if you are from Rails background, this layout would seem obvious. However, once you start to scale your application, this layout would cause various folders to be open at the same time. Be it Vim, Visual Studio, or Sublime, investing a lot of time scrolling through the directory tree becomes a common practice.


Therefore, it is always suggested to group files based on their features instead of type.















This directory structure makes it extremely easy to find files related to a specific feature, which will automatically accelerate your development.


2. Dependency Injection

Dependency injection is apparently one of the best patterns of AngularJS. It makes testing a lot easier for developers while making it more evident upon which a specific object relies. The framework is extremely scalable on how things can be injected.


The easiest version of Dependency Injection needs simply passing the dependency name into the function like:


var app = angular.module(‘app’,[]);
app.controller(‘MainCtrl’, function($scope, $timeout){
}, 1000);


It is clearly evident that $scope and $timeout are the two arguments on which MainCtrl depends upon.

This will work well unless you decide on going to production and wish to minify the code.


Here is the example using UglifyJS:

var app=angular.module(“app”,[]);app.controller(“MainCtrl”,function(e,t){t(function(){console.log(e)},1e3)})


if you look closely you would realize there isn’t any way to notify AngularJS about MainCtrl’s dependency.


Therefore, it is suggested to pass an array of strings to dependencies, where the last array element being a function which considers all the dependencies as arguments.


app.controller(‘MainCtrl’, ['$scope', '$timeout', function($scope, $timeout){ $timeout(function(){ console.log($scope); }, 1000); }]);


And then minify the code with evident dependencies that the framework knows how to interpret.




3. Using jQuery


Almost every developer is familiar with jQuery, a popular library for AJAX operations, for managing events and creating DOM manipulation easy. On the other hand, AngularJS is a framework that is employed in the development of flexible applications. It is all about developing and testing different application, and thus cannot be employed in augmentation of HTML pages. Therefore, it cannot be used with jQuery.


What you can do is to take your code beyond HTML syntax simply it has been declared.


The Javascript Framework has enough features and thus, a developer must figure out what features they can use before opting jQuery. If you need DOM manipulation, do it only in directives, which keeps jQuery out of your application development.


4. Not optimizing the application


If you don’t optimize your application, it will surely lead to AngularJS errors.


Have a look at a code inside the controller that will not only work slow but migh also give you an error.


this.maxPrice = ’100′;

this.price = ’55’;

$scope.$watch(‘MC.price’, function (newVal) {

if (newVal || newVal === 0) {

for (var i = 0; i < 987; i++) {






The best solution for this would be to put a timeout in place on the input.


5. Overlooking controllerAs Syntax


To assign a model to a controller object, you need to use $scope. However, it doesn’t considered to be the best way to perform the task. Using controllerAs Syntax is considered to be the most efficient and the best alternative.


As an instance:

function MainController($scope) { = 1;

var that = this;

var setBar = function () {

// = {someProperty: 2}; = {someProperty: 2};


// there are other conventions:

// var MC = this;

//; when using ‘this’ inside setBar()



As a matter of fact, most of these mistakes occur when you least expect them. It indeed helps when you know what causes the error and how to fix it without having to invest a lot of efforts.


If you want to make the most of this framework, then it is mandatory that you prevent these common mistakes from happening in your code to get the desired goals in a short span of time.



Author Bio:

Jason is expert in developing WordPress Websites and earns his daily bread from the same. He likes to stay updated with the latest tech advancements and also loves to contribute to the same. For those who are looking to Hire WordPress Programmer can match pace with the competitiveness can count on Jason for it.


Be Sociable, Share!



    Leave a response

    Powered by Wordpress and Crunchy wordpress themes | Designed by Wall Street Journal Subscription. In collaboration of Free Banner Maker, Debt Consolidation Loan and Wedding To Do List