1

I am new with Angular,

Then I want to get model data using javascript.

I want if is possible to getting with javascript a model value using the $scope and html element?

Is this the way to do??

<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>
4
  • 2
    ng-model is useless on a tr. ng-model is used on form elements (inputs, textarea, select), in order to populate the model with what the user enters/selects. A user doesn't enter anything in a tr. Why would you use the dom to find the nth element of an array that is in your model? Just use $scope.taxes.list[1] in your controller. Commented Jan 20, 2015 at 21:54
  • great.. How to I could to do a Binding Data with a TR?? sorry If my question is very Bad. Commented Jan 20, 2015 at 21:56
  • You're already doing it. Just drop the ng-model which is useless: each tr has two tds, and each td shows a n attribute of the current tax object. What's the problem? What are you trying to achieve? Commented Jan 20, 2015 at 21:59
  • I have a keyboard listener (for all.. this works well).. But I am adding Angular and I want to use the same keyboard listener.. and when the user press a key (example: Enter, Escape, Key Up, Key Down) I want to change the model data of a row. The keyboard lister pass me the html element. Commented Jan 20, 2015 at 22:04

1 Answer 1

1

It's not recommended to work with DOM elements in your controllers:

> 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).

Instead you use data binding to separate view and business logic. See developer guide for more details.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.