javascript - Using a variable within AngularJS expression? -


i'm new angular, wondering able use js variable within angularjs expression (not sure if it's called expression). simplest way can demonstrate this:

<code>     <script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>     <script>         var number = 10;     </script>     <div ng-app="">         <p>my expression: {{ 5 + number}}</p>     </div> </code> 

is there way this?

no, cannot use global variables (or functions) in angular expressions. angular expressions attributes, strings , not javascript code. angular parser ($parse service, sourse code) takes attributes, parses them , evaluates against scope object of angular app. in order use in angular expression must defined on corresponding scope object.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -