javascript - 无法使用 AngularJs 获取文本区域值

标签 javascript angularjs angularjs-directive angularjs-scope

<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 文本字段都通过 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/

相关文章:

javascript - 我该如何处理错误,忽略它并继续使用该功能?不和谐.js

javascript - AngularJS,MVC。未知提供者 : $ScopeProvider <- $Scope <- userCtrl

javascript - AngularJS View 未从与工厂关联的范围更新

javascript - 如何让 ng-class 与 $dirty 在指令中工作?

javascript - 通过在 php 中即时生成的浏览器缓存 JS 文件

javascript - map 区域 : onfocus=blur() works in IE but now adds an outline to Firefox?

angularjs - Angular Js无限滚动,带有固定标题

javascript - 如何在 ng-blur 中将输入元素作为参数传递?

javascript - 在 Angular Directive(指令)中完成 ng-repeat

javascript - AngularJS 指令 - 将函数作为参数传递给 "&"属性