Angularjs Examples

AJS Examples

AngularJS $scope.$eval() Function

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.


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

AngularJS $scope.$eval() Function Example

<!DOCTYPE html>        
<head> <!-- -->        
 <script src="//"></script>         
    <meta charset="utf-8">        
    <title>AngularJS $eval Example</title>        
var app = angular.module('app', []);        
     app.controller("EvalController", function($scope) { 
       $scope.intA = 23;
       $scope.intB = 54;
       $scope.result = $scope.$eval('intA +intB');   
<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>   
See Live Example