Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • AngularJS - $interpolate, $compile and $parse

    • 0
    • 1
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 905
    Comment on it


    There are three useful services provided by AngularJS for view rendering and evaluating expression which it uses internally.

    $interpolate :- This service simply takes a string and is used to evaluate expressions. We can run the entire string and this interpolate will give you the result. e.g usage of $interpolate-

    var string = 'I am {{name}}';
    $scope.name = 'Munmun';
    $interpolate(string)($scope);


    $complie :- This service takes the complete markup and converts a html string in a fully functional DOM element. This DOM would work same as a DOM element as it would have all linking and events. This uses $parse internally for evaluating expressions. e.g usage of $compile would be-

    var html = '<div ng-click='egclick();'>{{something}}</div>';
    $compile(html)($scope);


    $parse :- This service is used as a getter/setter for individual expression. It is basically used by $interpolate to evaluate single variable against a scope. e.g usage of $parse-
     

    $scope.msg = 'hello';
    $parse('msg')($scope); //this will result in hello
    $parse('msg').assign($scope,'happy');
    

     

 1 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: