Angularjs 在ng init中添加过滤器 {{hf.name}

Angularjs 在ng init中添加过滤器 {{hf.name},angularjs,angularjs-ng-repeat,angularjs-ng-init,Angularjs,Angularjs Ng Repeat,Angularjs Ng Init,如果可能的话,在ng init中进行过滤是很重要的,但我无法解决它,我无法使ng重复并创建作用域,然后将其传递给我的指令,因为它会启动无限摘要循环。您问题的答案是什么 您的代码段无法工作,因为ho和filter:search是不同的语句。在 <input ng-model="search.name" placeholder="Name" /> <tbody> <div ng-init="FilteredGeojson = ho|filter:search">

如果可能的话,在ng init中进行过滤是很重要的,但我无法解决它,我无法使ng重复并创建作用域,然后将其传递给我的指令,因为它会启动无限摘要循环。

您问题的答案是什么 您的代码段无法工作,因为
ho
filter:search
是不同的语句。在

<input ng-model="search.name" placeholder="Name" />

<tbody>
<div ng-init="FilteredGeojson = ho|filter:search">
<tr ng-repeat="hf in FilteredGeojson">
    <td>{{ hf.name }}</td>   
</tr>
</div>
</tbody>
</table>
<div leaflet-directive id="map" data="FilteredGeojson"></div>
。。。分配
FilteredGeojson=ho
在应用过滤器
|filter:search
之前完成,这不起作用

您需要像这样封装筛选值:

ng-init="FilteredGeojson = ho | filter:search"
ng-init="FilteredGeojson = (ho | filter:search)"
阿尔索 在ng init中进行过滤非常重要

对什么重要
ngInit
指令只在那里调用一次,因此当您更新过滤器时,
ngRepeat
中的项目不会被更新。但你需要这个,对吗

要实现这一点,您应该在
ngRepeat
指令中添加过滤器,如下所示:

ng-init="FilteredGeojson = ho | filter:search"
ng-init="FilteredGeojson = (ho | filter:search)"

{{hf.name}
例子
这两种解决方案都可以在中找到。

我使用了Sharikov Vladislav的例子。顺便说一下,谢谢

对我来说,这只是没有“过滤器”的工作:



(此页面没有控制器)

此处不需要
ng init
,只需临时使用
ng repeat

这里是最新的

以下是plnkr中的index.html

<div class="centerdivConteneur" ng-init="$root.breadcrumb.label = '<li><a href=\'#\'>Index</a></li><li>' +('Plan du site'|translate)+'</li>'">

安古拉斯普朗克
文件。写(“”);
FilteredGeojson.length:-{{FilteredGeojson.length}

{{search}} {{item.name}
当您使用输入框更改作用域上的
search
变量时,将更新
FilteredGeojson
。我更新了plnkr以显示这一点

另外,如果
Geojson
数组是一个长数组,那么可以像这样使用
limito
过滤器


让我知道它是否有用

还有一件事我想对其他指令使用ng init,当我做类似这样的事情时{{item.name}{{FilteredGeojson}}FilteredGeojson in没有改变,如何影响它呢?不,首先不要在注释中写代码。更新你的答案。我已经提供了充分工作的plnkr和它的ok。我回答你的问题了吗?如果您需要做更多的工作,请在问题中添加解释,但最好创建新的。这个问题解决了。在我的问题中没有解决。我在按范围过滤后将ng init传递到另一个指令中,您在plnkr中没有这样做,我问如何仅在ng init中进行过滤,如果我从ng-repeat中删除过滤器搜索,您的示例将不起作用。我的第二句话清楚地说,我不能使用ng-repeat@IOR88确切地为什么不能使用ngRepeat?这意味着您有复杂的体系结构问题。你根本没有解释。ngInit中的语句被触发1次,因此它不能与运行时过滤器一起工作:ngInit不会在ngInit上触发。另一种方法是在
$scope.filter
上使用
$watch
,但它非常可怕。你必须使用ngRepeat,你需要使用ngRepeat,仅此而已。