Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 角坐标中的插值_Angularjs_Angularjs Scope_Angularjs Controller_Angularjs Watch_Angularjs Interpolate - Fatal编程技术网

Angularjs 角坐标中的插值

Angularjs 角坐标中的插值,angularjs,angularjs-scope,angularjs-controller,angularjs-watch,angularjs-interpolate,Angularjs,Angularjs Scope,Angularjs Controller,Angularjs Watch,Angularjs Interpolate,我试图理解Angular JS中的插值概念,我已经编写了这段代码。我试图在输入框中输入文本,并且基于文本区域中的模板标记,它应该替换变量并在previewText字段中动态更新最终消息。如何做到这一点 <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular.min.js"></script&

我试图理解Angular JS中的插值概念,我已经编写了这段代码。我试图在输入框中输入文本,并且基于文本区域中的模板标记,它应该替换变量并在previewText字段中动态更新最终消息。如何做到这一点

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body ng-app="myApp">
<div ng-controller="MyController">
<input ng-model="to" 
      type="email" 
      placeholder="Recipient" />
<textarea ng-model="emailBody"></textarea>
<pre>{{ previewText }}</pre>
</div>
</body>
<script>
angular.module('myApp', []).controller('MyController',function($scope,   $interpolate) {
  $scope.to = 'text'; //static value.Trying to make this dynamic. How     to achieve it??
 //      $scope.$watch('to',function(newValue,oldValue,scope)
  //{
    //$scope.to = $interpolate($scope.to)($scope);
  //});
  $scope.emailBody = 'Hello {{ to }},My name is Ari too!';
  // Set up a watch
  $scope.$watch('emailBody', function(body) {
    if (body) {
      var template = $interpolate(body);
      $scope.previewText = 
        template({to: $scope.to});
    }
  });
  });



 </script>
 </html>

JS-Bin
{{previewText}}
角度.module('myApp',[]).controller('MyController',函数($scope,$interpolate){
$scope.to='text';//静态值。正在尝试将此设置为动态。如何实现此设置??
//$scope.$watch('to',函数(newValue,oldValue,scope)
//{
//$scope.to=$interpolate$scope.to)($scope);
//});
$scope.emailBody='Hello{{{to}},我的名字也是Ari!';
//摆好手表
$scope.$watch('emailBody',函数(body){
如果(正文){
变量模板=$interpolate(主体);
$scope.previewText=
模板({to:$scope.to});
}
});
});

只需删除您的
$scope。观察
并将其替换为

ng-change="update()"
然后加上

Hello {{imagename}}! 您的

请注意,由于您已指定了
型号仅在输入值为电子邮件地址(不包括初始状态)时有效并设置


AngularJS使用嵌入表达式的插值标记提供文本节点和属性值的数据绑定

插值示例如下所示:

你好{{imagename}}!
谢谢成功了:)你能为我提供一些关于材料的建议吗?我能更好地理解角度插值概念吗?@ang123你似乎对它们理解得很好。当
更改为
模型时,您所缺少的只是一个更新
previewText
的钩子 Hello {{imagename}}!