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

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

在 Angular 8 中創(chuàng)建過(guò)濾管道

在 Angular 8 中創(chuàng)建過(guò)濾管道

智慧大石 2023-12-19 20:37:11
我在 Web 開(kāi)發(fā)方面有一些經(jīng)驗(yàn),但對(duì) Angular 還很陌生。我正在嘗試創(chuàng)建一個(gè)簡(jiǎn)單的過(guò)濾器來(lái)根據(jù)文本輸入過(guò)濾表的一列。我遇到的問(wèn)題是,當(dāng)您在文本輸入中輸入單個(gè)字母時(shí),所有結(jié)果都會(huì)被過(guò)濾掉。AnimalsComponent.tsimport { ApiService } from '../api.service';import { AnimalFilterPipe } from '../animal-filter.pipe'@Component({  selector: 'app-animals',  templateUrl: './animals.component.html',  styleUrls: ['./animals.component.css'],  providers: [AnimalFilterPipe]})export class AnimalsComponent implements OnInit {    animals = [];    constructor(private apiService: ApiService) { }    ngOnInit() {        this.apiService.getA().subscribe((data: any[])=>{              console.log(data);              this.animals = data;          })      }}動(dòng)物過(guò)濾管import { Pipe, PipeTransform } from '@angular/core';@Pipe({  name: 'animalFilter'})export class AnimalFilterPipe implements PipeTransform {  transform(animals: any, term: string): any {    //check if the search term is defined    if(!animals || !term) return animals;    //return updated animals array     animals.filter(function(animal){      return animal.Animal.toLowerCase().includes(term.toLowerCase());    })  }}動(dòng)物.html<div style="padding: 13px;">  <form id = "animalFilter">    <label>Filter by Animal:</label>    <input type="text" [(ngModel)]= "term" [ngModelOptions]="{standalone: true}"/>  </form>    <table>        <tr>            <th>Hemisphere</th>            <th>Type</th>            <th>Animal</th>            <th>Seasonality</th>            <th>Location</th>            <th>Time</th>            <th>Price</th>          </tr>            <td align="center">TBD</td>          </ng-template>        </tr>    </table></div>如果有人可以幫助我并給我一些關(guān)于我需要更改的內(nèi)容以及如何更好地前進(jìn)的建議,以便我可以創(chuàng)建更多的過(guò)濾管道和更多的自定義管道。
查看完整描述

1 回答

?
互換的青春

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

您剛剛忘記了 return 中的語(yǔ)句transform

return animals.filter(animal => animal.Animal.toLowerCase().includes(term.toLowerCase()));


查看完整回答
反對(duì) 回復(fù) 2023-12-19
  • 1 回答
  • 0 關(guān)注
  • 181 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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