-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular-$interpolate.html
32 lines (30 loc) · 1.24 KB
/
angular-$interpolate.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>angular-$interpolate</title>
<script type="text/javascript" src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body ng-app="app" ng-controller="MyController">
<input type="email" ng-model="to">
<textarea name="name" rows="8" cols="80" ng-model="emailBody"></textarea>
<pre>{{previewText}}</pre>
<script type="text/javascript">
var app = angular.module('app', []);
app.controller('MyController', ['$scope', '$interpolate', '$timeout', function($scope, $interpolate, $timeout){
// 手动运行模板编译
$scope.$watch('emailBody', function(body){
if(body){
var template = $interpolate(body);
$scope.previewText = template({to: $scope.to});
}
});
// 模拟输入
$timeout(function(){
$scope.to = '[email protected]';
$scope.emailBody = 'Dear {{to}}: This is a test mail.';
}, 1000);
}]);
</script>
</body>
</html>