gpt4 book ai didi

javascript - Angular : access data

转载 作者:行者123 更新时间:2023-11-30 08:32:13 25 4
gpt4 key购买 nike

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

我不明白 Angular 如何访问 DOM 数据。

在所有示例中,我都看到数据是在 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.'}
];
});

例如,如果我有一个从其他来源填充​​的表格怎么办。

<table>

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

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

...

</table>

假设我想在用户单击某个按钮时对这些表格行执行某些操作(例如,过滤其中的一些行)。我如何获取 Controller 中表格中的所有数据。

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

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

但我不像教程那样从 Controller 加载数据。就我而言,它已经存在了。我只需要得到它进行操作。怎么办?

最佳答案

简单的回答是,你不能。 Angular 只能从 Controller 中操作绑定(bind)到 $scope 的数据(或使用 ng-init,但 Controller 使它更容易)。

关于javascript - Angular : access data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36006304/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com