javascript - AngularJS - 使用 ng-model 时忽略输入文本框上的值属性?

标签 javascript html angularjs

如果我将一个简单的输入文本框值设置为下面的“bob”,则使用 AngularJS。如果添加了 ng-model 属性,则不会显示该值。

    <input type="text"
           id="rootFolder"
           ng-model="rootFolders"
           disabled="disabled"
           value="Bob"
           size="40"/>

任何人都知道一个简单的解决方法来将此输入默认为某些东西并保留 ng-model?我尝试使用具有默认值的 ng-bind 但这似乎也不起作用。

最佳答案

这是期望的行为,您应该在 Controller 中定义模型,而不是在 View 中。

<div ng-controller="Main">
  <input type="text" ng-model="rootFolders">
</div>


function Main($scope) {
  $scope.rootFolders = 'bob';
}

关于javascript - AngularJS - 使用 ng-model 时忽略输入文本框上的值属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10610282/

相关文章:

javascript - 使用 Typescript 1.5 时 Angular 为 null 并且需要

java - Spring AngularJS 获取请求

javascript - 使用 es6 制作 uniqBy

javascript - 从查询字符串参数推断正确的数据类型

javascript - laravel 如何将数据传递到另一个 View

CSS 类合并

html - 导航栏 'overflow' 无法删除

javascript - Chrome : not "remembering" the choice to allow access to microphone

javascript - 使用 $().html 时 mdui 的一些效果消失了

angularjs - 测试 ui.router $stateChangeSuccess