angularjs - $parse vs $eval ? which one is best practice? -


i know $parse , $eval both operate on angular expressions.then why angular team created these 2 ?

i checked in angular library, $eval defined that:

$eval: function(expr, locals) {         return $parse(expr)(this, locals);       } 

so difference between :

$parse(expr)(context, locals); 

and

$eval: function(expr, locals) {         return $parse(expr)(this, locals);       } 

i want know 1 best practice ? , when use these 2 ?

as noticed,

$parse(expr)($scope, locals) 

is exactly equivalent to

$scope.$eval(expr, locals) 

but, $parse more "fundamental" operation $eval, , so, $parse once in 1 place (for example, in compile function of directive):

var parsedexpr = $parse(tattrs.p1); 

and use repeatedly elsewhere (for example, in controller function)

var childscope1 = $scope.$new(); var childscope2 = $scope.$new();  var r1 = parsedexpr(childscope1); var r2 = parsedexpr(childscope2); 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -