Using JavaScript in AngularJS Expressions

In this final example we take a look at some additional JavaScript interactions within the scope. As described previously, much of the JavaScript functionality is supported in AngularJS expression. To illustrate this better, the example shows some array manipulation as well as utilizing the JavaScript Math object within expressions.

Listing 5.5 creates a simple AngularJS controller that contains two arrays in the scope. Notice that on line 3, the following statement adds a Math variable to the scope by assigning it to windows.Math. This is necessary to use the JavaScript Math functionality because only the scope variables are available when AngularJS expressions are evaluated:

$scope.Math = window.Math; ...

Get Learning AngularJS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.