$interpolate服务

要在字符串模板中做插值操作,需要在你的对象中注入$interpolate服务

$interpolateProvider

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

</html>


$interpolate服务_第1张图片
  

 

 

 

 

 

 

你可能感兴趣的:($interpolate服务)