Javascript 角度:访问数据

Javascript 角度:访问数据,javascript,angularjs,controller,Javascript,Angularjs,Controller,我刚开始学习angular,现在我很困惑 我不明白angular是如何访问DOM数据的 在我看到的所有示例中,数据都是在控制器内初始化的: phonecatApp.controller('PhoneListCtrl', function ($scope) { $scope.phones = [ {'name': 'Nexus S', 'snippet': 'Fast just got faster with Nexus S.'}, {'name': 'Motorol

我刚开始学习angular,现在我很困惑

我不明白angular是如何访问DOM数据的

在我看到的所有示例中,数据都是在控制器内初始化的:

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.'}
  ];
});
例如,如果我有一个表格是从另一个来源填写的呢

<table>

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

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

    ...

</table>

约翰
约翰逊
30
大卫
戴维森
23
...
假设当用户单击某个按钮时,我想对这些表行执行一些操作(例如,过滤其中的一些行)。如何获取控制器中表中的所有数据

我可以像教程中那样在中继器上应用过滤器

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


  • 但我不像教程那样从控制器加载数据。就我而言,它已经在那里了。我只需要把它拿来操纵。怎么做?

    简单的答案是,你不能。Angular只能在控制器内操作绑定到$scope的数据(或使用ng init,但控制器使其更容易)。

    简单的答案是,您不能。Angular只能在控制器内操作绑定到$scope的数据(或使用ng init,但控制器使其更简单)。

    Angular不访问DOM来检索数据,它访问您传递给它的数据(通常在控制器内)并使用它生成DOM

    Angular不访问DOM来检索数据,它访问您传递给它的数据(通常在控制器内部),并使用它生成DOM