<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
值。除input
之外,所有textarea
文本字段都通过控制器。我究竟做错了什么 ?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
分配任何内容。 (但是也许您早先定义了它,但是代码中没有显示它)。
实际上,让它正常工作没有问题。我将警报包装在绑定到“提交”按钮的函数中。我能够得到价值。 See my example。
我还随意更改了您的$scope
。建议每个ngModel
的名称中都包含一个.
。因此,应该使用tbAddress
而不是tb.address
。它与如何处理角度继承有关。
参考:
Why don't the AngularJS docs use a dot in the model directive?
The Dot - egghead video
Google results for 'angular use dots in models'