angular.js $parse的用法demo

    xiaoxiao2021-04-02  33

    《angular权威教程》中的$parse的用法Page20页中给了一个demo,无法运行出正确结果,后台也没有报错

    做了如下更改后,可正确运行,但目前无法确定自己的使用方法是否正确。仅供各位看官参考

    <!doctype html>

    <html ng-app="myApp"> <head>   <title>Parse Expression Example</title>   <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js"></script> </head> <body>   <div ng-controller="MyController">     <input ng-model="expr"             type="text"             placeholder="Enter an expression" />     <div>{{ parsedExpr }}</div>   </div>   <script>     angular.module('myApp', [])     .controller('MyController',     ['$scope', '$parse', function($scope, $parse) {       $scope.$watch('expr', function(newVal, oldVal, s) {         if (newVal !== oldVal) {           var parseFun = $parse('expr');           console.log(parseFun);           s.parsedExpr = parseFun(s);         }       });     }]);   </script> </body> </html>
    转载请注明原文地址: https://ju.6miu.com/read-665775.html

    最新回复(0)