繁体   English   中英

无法使用AngularJs获得textarea值

[英]can't getting textarea value using AngularJs

<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>&nbsp;</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文本字段都通过控制器。 我究竟做错了什么 ?

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分配任何内容。 (但也许您早先定义了它,但是代码中没有显示它)。

实际上,让它正常工作没有问题。 我将警报包装在绑定到“提交”按钮的函数中。 我能够得到价值。 看我的例子

我还自由更改了$scope 建议每个ngModel都有一个. 以它的名字。 因此,而不是tbAddress它应该是tb.address 它与如何处理角度继承有关。

参考:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM