AngularJS - 当使用 ng-model 时,输入文本框上的 Value 属性会被忽略吗? [英] AngularJS - Value attribute on an input text box is ignored when there is a ng-model used?
本文介绍了AngularJS - 当使用 ng-model 时,输入文本框上的 Value 属性会被忽略吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我将一个简单的输入文本框值设置为类似于下面的bob",则使用 AngularJS.如果添加了 ng-model
属性,则不会显示该值.
有人知道一个简单的解决方法来将此输入默认为某些内容并保留 ng-model
吗?我尝试使用带有默认值的 ng-bind
但这似乎也不起作用.
解决方案
这是期望的行为,您应该在控制器中定义模型,而不是在视图中.
<input type="text" ng-model="rootFolders">功能主($范围){$scope.rootFolders = 'bob';}
Using AngularJS if I set a simple input text box value to something like "bob" below. The value does not display if the ng-model
attribute is added.
<input type="text"
id="rootFolder"
ng-model="rootFolders"
disabled="disabled"
value="Bob"
size="40"/>
Anyone know of a simple work around to default this input to something and keep the ng-model
? I tried to use a ng-bind
with the default value but that seems not to work either.
解决方案
That's desired behavior, you should define the model in the controller, not in the view.
<div ng-controller="Main">
<input type="text" ng-model="rootFolders">
</div>
function Main($scope) {
$scope.rootFolders = 'bob';
}
这篇关于AngularJS - 当使用 ng-model 时,输入文本框上的 Value 属性会被忽略吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文