1

Just started learning angular and I'm stumped at the moment.

I don't understand how angular accesses DOM data.

In all examples I've seen data is being initialized inside a controller:

phonecatApp.controller('PhoneListCtrl', function ($scope) {
  $scope.phones = [
    {'name': 'Nexus S',
     'snippet': 'Fast just got faster with Nexus S.'},
    {'name': 'Motorola XOOM™ with Wi-Fi',
     'snippet': 'The Next, Next Generation tablet.'},
    {'name': 'MOTOROLA XOOM™',
     'snippet': 'The Next, Next Generation tablet.'}
  ];
});

What if I have a table that's been filled from another source for example.

<table>

    <tr>
        <td> John </td>
        <td> johnson </td>
        <td> 30 </td>
    </tr>

    <tr>
        <td> David </td>
        <td> Davidson </td>
        <td> 23 </td>
    </tr>

    ...

</table>

Let's say I want to do something with those table rows (filter some of them, for example) when a user clicks a certain button. How do I get all the data that's in a table in my controller.

I could apply a filter on a repeater like in the tutorial

<li ng-repeat="phone in phones | filter:query">
   {{phone.name}}
   <p>{{phone.snippet}}</p>
</li>

but I don't load data from a controller like the tutorial does. In my case it's already there. I just need to get it for manipulation. How?

2 Answers 2

4

The simple answer is, You can't. Angular can only manipulate data that's binded to the $scope from within a controller (or using ng-init, but the controller makes it easier).

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

Comments

1

Angular does not access DOM to retrieve data, it accesses data you pass to it (usually inside the controller) and uses it to generate DOM.

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.