AngularJS - 在输入文本框Value属性时,使用的是NG-模式被忽略? [英] AngularJS - Value attribute on an input text box is ignored when there is a ng-model used?

查看:168
本文介绍了AngularJS - 在输入文本框Value属性时,使用的是NG-模式被忽略?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用AngularJS如果我设置一个简单的输入文本框的值类似下面的鲍勃。如果添加了 NG-模型属性的值不会显示。

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"/>

任何人都知道一个简单的工作围绕该输入默认的东西,并保持 NG-模型?我试图用 NG-绑定使用默认值,但似乎没有任何工作。

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 - 在输入文本框Value属性时,使用的是NG-模式被忽略?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆