danishwebindia Posted November 17, 2014 Share Posted November 17, 2014 (edited) <div ng-app="" ng-init="a=0;b=0;"> <input type="text" ng-model="a" /> <input type="text" ng-model="b" /> {{c}} </div> <script> $scope.Math=Math; var c=Math.pow (a, b ) ; </script> Edited November 17, 2014 by danishwebindia Link to comment Share on other sites More sharing options...
niche Posted November 17, 2014 Share Posted November 17, 2014 What's your question? Link to comment Share on other sites More sharing options...
danishwebindia Posted November 17, 2014 Author Share Posted November 17, 2014 (edited) I want to find power i.e a=2; b=3; c=8 in angular js Edited November 17, 2014 by danishwebindia Link to comment Share on other sites More sharing options...
Ingolme Posted November 17, 2014 Share Posted November 17, 2014 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 More sharing options...
danishwebindia Posted November 17, 2014 Author Share Posted November 17, 2014 (edited) <div ng-app="" ng-init="a=0;b=0;"> <input type="text" ng-model="a" /> <input type="text" ng-model="b" /> {{(Math.pow(a, b ))}} //Want to value here not in alert// </div> your alert is working Edited November 17, 2014 by danishwebindia Link to comment Share on other sites More sharing options...
Ingolme Posted November 17, 2014 Share Posted November 17, 2014 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 More sharing options...
thescientist Posted November 17, 2014 Share Posted November 17, 2014 @danishwebindia A couple issues I see (in order of precedence) You haven't declared anything in ng-app. Without it, Angular will not initialize / bootstrap your application 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 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 More sharing options...
dsonesuk Posted November 17, 2014 Share Posted November 17, 2014 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 More sharing options...
danishwebindia Posted November 19, 2014 Author Share Posted November 19, 2014 thank you Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now