我有以下html:
<!DOCTYPE HTML>
<html>
<head>
<title>Basic</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js type="text/javascript">
</script>
</head>
<body>
<div ng-app="myApp">
<input ng-model="to" type="email"
placeholder="Recipient here.."/>
<textarea ng-model="emailBody"
placeholder="Email body here..">
</textarea>
<h2> {{ emailBody }} </h2>
</div>
</body>
</html>
我从textArea引用了emailBody数据,但未绑定关联的数据。只是按字面意思输入{{emailBody}}。
我究竟做错了什么?
假设您是第一次使用Angular,您可能想使用不带值的“ ng-app”参数,该参数将设置注入上下文而不将其映射到命名的应用程序控制器(在示例中缺失)。还要注意,您缺少脚本标记的src参数的右引号。
这是您的示例,使用这两个修复程序,按预期工作。
<!DOCTYPE HTML>
<html ng-app>
<head>
<title>Basic</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js" type="text/javascript"></script>
</head>
<body>
<div>
<input ng-model="to" type="email" placeholder="Recipient here.."/>
<textarea ng-model="emailBody" placeholder="Email body here..">
</textarea>
<h2> {{emailBody}} </h2>
</div>
</body>
</html>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句