Angular 插值字符串

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <script src="js/angular.min.js"></script>
    <script>
        angular.module('myApp', []).controller('MyController', function($scope, $interpolate) {
            // 设置监听
            $scope.$watch('emailBody', function(body) {
                if (body) {
                    var template = $interpolate(body)
                    $scope.previewText = template({to: $scope.to})
                }
            })
        })
    </script>
</head>
<body ng-app="myApp">
    <div ng-controller="MyController">
        <input ng-model="to" type="text" placeholder="Recipient">
        <textarea ng-model="emailBody"></textarea>
        <pre>{{ previewText }}</pre>
    </div>
</body>
</html>

原文地址:https://www.cnblogs.com/jzm17173/p/6640979.html