我是新来的,
然后,我想使用javascript获取模型数据。
如果有可能的话,我想使用$scope和html元素获得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>发布于 2015-01-20 21:58:51
不建议在控制器中使用DOM元素:
> 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).相反,您可以使用数据绑定来分离视图和业务逻辑。有关更多详细信息,请参阅开发人员指南。
https://stackoverflow.com/questions/28055788
复制相似问题