Web programming: AngularJS, part 2

The tutor shows an example of AngularJS in action, with JavaScript’s Math.pow(x,y) function.



JavaScript’s function Math.pow(3,4) evaluates 34, giving the answer 81. In that expression, 3 is the base, while 4 is the exponent.

Below, you can input a base and exponent and receive the answer from JavaScript’s Math.pow(base,exponent).

base, exponent ,

{{base}} raised to exponent {{exponent}} is {{answer()}}

The notable feature of this form is that it’s handled with AngularJS, which binds values as they are entered with expressions elsewhere on the page. The reason this page needs back-end code is to support the Math.pow() function, which seems unavailable in AngularJS without being brought into the scope, perhaps as follows:

var app0=angular.module(“theApp”,[]);
app0.controller(“theFnc”, function($scope){
$scope.base=”base”;
$scope.exponent=”exponent”;
$scope.answer=function(){
return Math.pow($scope.base,$scope.exponent);
}});

I’ll be talking more about AngularJS in coming posts:)

Source:

w3schools.com

w3schools.com

Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Tagged with: ,

Leave a Reply