Wednesday, 15 April 2015

angularjs - Angular code from ng-book -


I am reading ng-books and there are some codes that I am not very short:

 < Code> & lt; Div ng-controller = "MyController" & gt; & Lt; Input ng-model = "expr" type = "text" placeholder = "insert expression" /> & Lt; H2 & gt; {{ParsedValue}} & lt; / H2 & gt; & Lt; / Div & gt; Angular.module ("myApp", []). Controller ('MyController', function ($ radius, $ paras) {$ scope. $ Watch ('expr', function (newVal, oldVal, scope) {if (newVal! == oldVal) {/ Let's translate our parseFun Set par parseFun = $ parse (newVal); // Get the value of the parsed expression $ scope.parsedValue = parseFun (scope);}})}};  

I'm guessing parseFun () scope.expr evaluation If this is the case then how is this asset evaluated?

parsfn $ parse (newVal) In this case, they mean that it means that the parsfun There will be a new prose expression. Then they retrieve the value of the parsed expression by passing the scope given with the clock function callback with the parsfun (scope)

Note: In real angular development you rarely see a watch statement You can use the controller


No comments:

Post a Comment