首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AngularJS - Get ng- html元素模型

AngularJS - Get ng- html元素模型
EN

Stack Overflow用户
提问于 2015-01-20 21:50:46
回答 1查看 2.2K关注 0票数 1

我是新来的,

然后,我想使用javascript获取模型数据。

如果有可能的话,我想使用$scope和html元素获得javascript的模型值吗?

是这样做的吗??

代码语言:javascript
复制
<div class="tax-concept-form" ng-controller="TaxesController as taxes" ng-init="taxes.init()">
    <table cellspacing="0" class="taxes-table table ctrl-3" id="tabla_edicion" tabindex="">
        <tbody>
            <tr ng-repeat="_tax in taxes.list" class="javorai-master-detail-row item-selectable" ng-model="_tax" id="row_{{_tax.id}}">
                <td>{{_tax.tax.description}}</td>
                <td>{{_tax.tax.rate}}</td>
            </tr>
        </tbody>
   </table>
<script>
//I have a angular $scope
//some javascript

var el = document.getElementById('row_1');

//I want the tax of row_1
</script>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-20 21:58:51

不建议在控制器中使用DOM元素:

代码语言:javascript
复制
> Do not use controllers to:

Manipulate DOM — Controllers should contain only business logic. Putting any presentation logic into Controllers significantly affects its testability. Angular has databinding for most cases and directives to encapsulate manual DOM manipulation.
Format input — Use angular form controls instead.
Filter output — Use angular filters instead.
Share code or state across controllers — Use angular services instead.
Manage the life-cycle of other components (for example, to create service instances).

相反,您可以使用数据绑定来分离视图和业务逻辑。有关更多详细信息,请参阅开发人员指南

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28055788

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档