Jump to content

find math.pow in angular js


danishwebindia

Recommended Posts

You should be able to access Math without $scope.

 

Did you try just calling alert(Math.pow(2, 3)); to see if it's working?

 

If that doesn't work, check the browser console for error messages and let me know what they say.

Link to comment
Share on other sites

I don't fully understand AngularJS. Is it server-side or client-side? The site mentions node.js which is server-side.

 

Anyways, I found the same question here: http://stackoverflow.com/questions/12740329/math-functions-in-angular-bindings

 

Perhaps that will be useful.

Link to comment
Share on other sites

@danishwebindia

A couple issues I see (in order of precedence)

  1. You haven't declared anything in ng-app. Without it, Angular will not initialize / bootstrap your application
  2. You have no controller. You need to have ng-controller="xxx" and create a controller in Angular to load your code and establish $scope in your DOM / application
  3. c isn't on $scope

 

I would suggest you go back through and review the Angular tutorials and learn some of the basics. It does have a bit of a learning curve, but a simple little calculator like application like you are trying should be fairly straightforward.

 

@Ingolme

Angular is a front end MVC Javascript framework developed by Google.

Link to comment
Share on other sites

You can't directly run math function within curly brackets, but you can call function using $scope to run a function with Math.pow()

        <div ng-app="" ng-init="a = 0;                b = 0;"  ng-controller="formController">            <input type="number" ng-model="a" />            <input type="number" ng-model="b"  />            {{topow()}}        </div>        <script>            function formController($scope)            {                $scope.topow = function() {                    return Math.pow($scope.a, $scope.;                };            }        </script>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...