Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 数据未绑定到输入文本文件中的作用域变量_Angularjs - Fatal编程技术网

Angularjs 数据未绑定到输入文本文件中的作用域变量

Angularjs 数据未绑定到输入文本文件中的作用域变量,angularjs,Angularjs,这是我的HTML标记: <form name="quotaForm"> <div class="form-group"> <label for="">username:</label> <input type="text" name="nameFiled" ng-model="username" class="form-control"> </div&

这是我的HTML标记:

<form name="quotaForm">
    <div class="form-group">
        <label for="">username:</label> 
        <input type="text" name="nameFiled"
               ng-model="username" class="form-control">
    </div>

    <button class="btn btn-primary" ng-click="updateQuota()">Update</button>
</form>

尽管我在这里没有看到您的所有代码,但我可以很有把握地打赌这是一个范围问题。如果在视图中使用的指令正在创建一个新的作用域(如ng If),则需要引用父级。视图中的ng model=“$parent.username”将修复此问题:

<form name="quotaForm">
  <div class="form-group">
    <label for="">username:</label> 
    <input type="text" name="nameFiled" ng-model="$parent.username" class="form-control">
  </div>

  <button class="btn btn-primary" ng-click="updateQuota()">Update</button>
</form>

用户名:
更新

但就像我说的,这只是一个猜测。

摆弄一切都很好我想问题出在你的代码中的其他地方提供完整的代码:-)你还发现了什么吗?@squiroid你是对的,她错过了一些其他的东西。我检查了你共享的JSFIDLE,在这里它工作很好。但无法在我的代码中找出问题所在。这种类型的数据绑定问题很久以前就发生过,当时我使用$scope.quotaForm.namefield.$modelValue获取数据。如何在此处使用$parent?如果此HTML嵌套在新创建的作用域中,$parent将引用控制器作用域变量。对吗?我可能是错的。是的。如果它是嵌套的,你可能是对的。但是提问者没有给出任何代码。是的,因此我的答案以“即使我没有看到你的所有代码,我可以很安全地打赌”开头,以“但就像我说的,这只是一个猜测”结尾:)。我认为这可能是问题的原因,因为它在过去给我造成了巨大的伤害。
<form name="quotaForm">
  <div class="form-group">
    <label for="">username:</label> 
    <input type="text" name="nameFiled" ng-model="$parent.username" class="form-control">
  </div>

  <button class="btn btn-primary" ng-click="updateQuota()">Update</button>
</form>