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
Post a Comment