对于 $parse服务,将angular 表达式转换为一个函数
angular.module("MyApp",[])
.controller("MyController", function($scope, $parse){
var context = {
name: "dreamapple"
}; // 因为这个解析的语句中含有我们想要解析的表达式,
// 所以要把不相关的用引号引起来,整体然后用+连接
var expression = "'Hello ' + name";
// 返回一个函数,这个函数就是
var parseFunc = $parse(expression);
// 传递参数,执行 这个函数。
$scope.ParsedValue = parseFunc(context);
});
$parse(expression)
expression: angular js 表达式
return func(context, locals) 函数
$parse 典型的使用是 放在设置字符串表达式