无法使用 AngularJs 获取 textarea 值 [英] can't getting textarea value using AngularJs

查看:29
本文介绍了无法使用 AngularJs 获取 textarea 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<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 文本字段都通过控制器.我做错了什么?

I'm not be able to get textarea value using AngularJS. All the input text fields are getting through the controller except the textarea. What am I doing wrong ?

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); 就在那里,当然它会以 结尾未定义.此时没有任何内容分配给 $scope.tbaddress.(但也许你之前已经定义了它,但它只是没有显示在代码中).

If you have alert($scope.tbAddress); positioned right there, of course it'll end up as undefined. Nothing has been assigned to $scope.tbaddress at this point. (but maybe you have it defined earlier, but it's just not being shown in the code).

实际上我在让它工作时没有问题.我将警报包装在一个绑定到提交按钮的函数中.我能够获得价值.看我的例子.

I actually didn't have a problem getting it to work. I wrapped the alert in a function that is bound to the submit button. I'm able to get the value. See my example.

我还冒昧地稍微更改了您的 $scope.建议每个 ngModel 的名称中都有一个 ..所以应该是 tb.address 而不是 tbAddress.它与如何处理角度继承有关.

I also took the liberty of changing your $scope a bit. It's recommended that every ngModel has a . in it's name. So rather than tbAddress it should be tb.address. It has to do with how angular inheritance is handled.

参考:

这篇关于无法使用 AngularJs 获取 textarea 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆