<tr class="labels">
<td nowrap="nowrap">Address</td>
<td nowrap="nowrap"><label for="tbAddress"></label>
<textarea name="tbAddress" id="tbAddress" cols="39" rows="5" ng-model="$parent.tbAddress"></textarea>
</td>
</tr>
<tr>
<td> </td>
<td align="right">
<input type="submit" name="button" id="button" value="Submit Record" class="btns" />
<input type="reset" name="button2" id="button2" value="Cancel" class="btns" />
</td>
</tr>
我无法使用 AngularJS 获取 textarea
值。除了textarea
之外,所有input
文本字段都通过 Controller 获取。我做错了什么?
alert($scope.tbAddress);
var thisData = {
'name': $scope.tbFN,
'company': $scope.tbCompany,
'designation': $scope.tbDesignation,
'email': $scope.tbEmail,
'phone': $scope.tbPhone,
'mobile': $scope.tbMobile,
'address': $scope.tbAddress
};
警报未定义...
最佳答案
如果您将 alert($scope.tbAddress);
放置在那里,当然它最终会显示为 undefined
。此时尚未将任何内容分配给 $scope.tbaddress
。 (但也许您之前已经定义了它,但它只是没有在代码中显示)。
事实上,我在让它工作时没有遇到任何问题。我将警报包装在绑定(bind)到提交按钮的函数中。我能够获得值(value)。 See my example .
我还冒昧地更改了您的 $scope
。建议每个 ngModel
的名称中都包含 .
。因此,它应该是 tb.address
,而不是 tbAddress
。它与 Angular 继承的处理方式有关。
引用:
关于javascript - 无法使用 AngularJs 获取文本区域值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23294691/