第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何將過(guò)濾器應(yīng)用于*ngFor?

如何將過(guò)濾器應(yīng)用于*ngFor?

如何將過(guò)濾器應(yīng)用于*ngFor?顯然,Range2將使用管道而不是過(guò)濾器(如Angular 1中的過(guò)濾器)與ng一起過(guò)濾結(jié)果,盡管實(shí)現(xiàn)似乎仍然是模糊的,沒(méi)有明確的文檔。也就是說(shuō),我想要達(dá)到的目標(biāo)可以從以下的角度來(lái)看<div *ng-for="#item of itemsList" *ng-if="conditon(item)"></div>如何使用管道來(lái)實(shí)現(xiàn)?
查看完整描述

3 回答

?
qq_花開(kāi)花謝_0

TA貢獻(xiàn)1835條經(jīng)驗(yàn) 獲得超7個(gè)贊

基本上,您可以編寫(xiě)一個(gè)管道,然后在*ngFor指令。

在你的組成部分中:

filterargs = {title: 'hello'};items = [{title: 'hello world'}, {title: 'hello kitty'}, {title: 'foo bar'}];

在模板中,可以將字符串、數(shù)字或?qū)ο髠鬟f給管道以用于篩選:

<li *ngFor="let item of items | myfilter:filterargs">

在你的煙斗里:

import { Pipe, PipeTransform } from '@angular/core';@Pipe({
    name: 'myfilter',
    pure: false})export class MyFilterPipe implements PipeTransform {
    transform(items: any[], filter: Object): any {
        if (!items || !filter) {
            return items;
        }
        // filter items array, items which match and return true will be
        // kept, false will be filtered out
        return items.filter(item => item.title.indexOf(filter.title) !== -1);
    }}

記得把你的煙斗登記在app.module.ts;您不再需要在您的@Component

import { MyFilterPipe } from './shared/pipes/my-filter.pipe';@NgModule({
    imports: [
        ..
    ],
    declarations: [
        MyFilterPipe,
    ],
    providers: [
        ..
    ],
    bootstrap: [AppComponent]})export class AppModule { }

這是一個(gè)柱塞它演示了使用自定義過(guò)濾管和內(nèi)置片管來(lái)限制結(jié)果。

請(qǐng)注意(正如幾位評(píng)論員所指出的)有一個(gè)原因為什么沒(méi)有內(nèi)置的過(guò)濾管道的角度。


查看完整回答
反對(duì) 回復(fù) 2019-06-28
  • 3 回答
  • 0 關(guān)注
  • 1460 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)