Loading…

Get Schooled at New Horizons

Info and insights from New Horizons Computer Learning Centers. 22 locations to serve you.
Start exploring

Where AngularJS can fit into your web projects

Many companies are using AngularJS today, and you may wonder if it’s appropriate for your own web projects. The basic idea to AngularJS is that you can create advanced functionality by writing mainly attributes in HTML. AngularJS works as a declarative language, meaning that you specify what happens, but not the sequential steps that make it happen. For example, consider the following AngularJS code:

<input type=”text” ng-model=”userinput”>
<p>You have input {{userinput}}.</p>

When the user types text into the input element, the message in the paragraph element is updated. In straight JavaScript, the way you’d do this would be with events, such as onchange. While that gives you a lot of control over exactly what happens, it does require you to write code to handle a number of different contingencies. The code above actually updates even as a user types each letter (not just when the user leaves the box), but also works if a user copy/pastes into the text box. Handling user input as smoothly as AngularJS does is actually much more complicated in JavaScript than just putting in an onchange event.

Using AngularJS is really a lot like a spreadsheet. The example above works similarly to typing into Excel a formula such as “=A1”. The cell simply updates whenever cell A1 is updated. AngularJS also lets you define more complex formulas (using expressions and controllers); and again, these work very similarly to formulas in Excel, except that controllers allow you to define your own formulas using JavaScript functions.

Here are three qualities that make AngularJS very attractive to companies:

  • Rapid development, especially for those kinds of tasks that are particularly idiomatic to AngularJS
  • Ability for HTML developers to easily work with interactive functionality, while seasoned JavaScript developers can develop more complex functionality separately
  • Less complexity when one needs to make changes, because the heavy lifting for handling events is done by the core library
  • Separation of concerns through MVC-based architecture

That said, AngularJS is not a magic bullet to solve all front-end problems. To see whether it’s right for your project, it’s important to learn those things that it does very well as well as its quirks. If what you’re trying to do differs significantly from AngularJS’s philosophy, then you may find yourself writing extra code to force it to fit your needs. In a nutshell, AngularJS is great at making elements on the page reflect user actions elsewhere on the page, such as for the following tasks and more:

  • Calculations, totals, and formulas
  • Menus and other navigational tools
  • Changing the display according to user preferences
  • Filtering results

On the other hand, certain specialized projects, where you want to control and fine-tune exactly what happens event-wise or performance-wise, may be less suitable to AngularJS.

Share

Leave a Reply