我是 AngularJS 的新手,我正在经历 this链接,我很好奇使用 ng-bind 对文本框控件进行实验。但它不起作用。
<html>
<title>AngularJS First Application</title>
<body>
<h1>Sample Application</h1>
<div ng-app="">
<p>Enter your Name: <input type="text" ng-model="name"></p>
<input type ="text" ng-bind="name" />
</div>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
</body>
</html>
如何使用 ng-bind 填充文本框?
最佳答案
因为,ngBind 属性告诉 Angular 替换 文字内容具有给定表达式的值的指定 HTML 元素,并更新 文字内容当该表达式的值发生变化时,您将无法绑定(bind)到输入框:
<input type ="text" ng-bind="name" />
您可以改为使用 ng-value
<input type="text" ng-value="name" />
或者您可以使用 value 属性中的模型填充输入框。
<input type="text" value="{{name}}" />
看到这个codepen
关于angularjs - 如何使用 ng-bind 填充文本框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29227480/