AngularJS $eval Method

The AngularJS $eval method is used to executes the AngularJS expression on the current scope and returns the result. In AngularJS, expressions are similar to JavaScript code snippets that are usually placed in bindings such as {{ expression }}. AngularJS used internally $eval to resolve AngularJS expressions, such as {{variable}}.

The important difference between $eval and $parse is that $eval is a scope method that executes an expression on the current scope, while $parse is a globally available service. The $eval method takes AngularJS expression and local variable object as parameter.

Syntax

$eval([expression], [locals]);

Example 1

<!DOCTYPE html>        
<html>        
<head> <!-- www.techstrikers.com -->        
 <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.1/angular.min.js"></script>         
    <meta charset="utf-8">        
    <title>AngularJS $eval Example</title>        
  <script>        
var app = angular.module('app', []);        
     app.controller("EvalController", function($scope) { 
       $scope.intA = 23;
       $scope.intB = 54;
       $scope.result = $scope.$eval('intA +intB');   
    });     
</script>        
</head>        
<body style="background-color:#DDE4E9;">        
  <fieldset style="background-color:#DDE4E9;">                    
    <legend>AngulerJS $eval Method Example</legend>         
  <div ng-app="app">              
    <div ng-controller="EvalController">         
      <input type="text" ng-model="intA" placeholder="Enter Number">  + <input type="text" ng-model="intB" placeholder="Enter Number">
<p style="font-family:Arial;color:yellow;background:steelblue;padding:3px;width:350px;"    
     >{{'Result :- ' + result}}</p>   
    </div>              
</div>        
 </fieldset>         
</body>        
</html>    
Try Now

See Also

AngularJS Built-in Filters
AngularJS Built-in Directives
AngularJS Expression
AngularJS Built-in Events
AngularJS Scope Methods
AngularJS Built-in Services
AngularJS Controller Inheritance
AngularJS Custom Directives


 
SHARE THIS IF YOU LIKE!
submit to reddit

SUBSCRIBE FOR LATEST UPDATES
HAVE WE CONNECTED ON FACEBOOK?
TOP TUTORIALSTOP CODE EXAMPLESTOP LIVE DEMOLINKSSTAY CONNECTED
HTML Tutorial
HTML5 Tutorial
Bootstrap3 Tutorial
Javascript Tutorial
TypeScript Tutorial
AngularJS Tutorial
CSharp Tutorial
PHP Tutorial
Developer Tools
Javascript
AngularJS
Google MAP API V3
ASP.NET
Javascript
AngularJS
Google MAP API V3
Contact Us
Advertise with Us
Privacy Policy
Disclaimer
Stay connected. We actually like you. If you want to get up to the minute updates, then connect with us on your fav below.
 
Twitter   Linkedin   Facebook   Google+    RSS   Pinterest
 
Protected by Copyscape Original Content Checker
 
 
Copyright ©2017 www.techstrikers.com Unauthorized reproduction/replication of any part of this site is prohibited.