4
我有2個選擇。如何編寫一個Angular ngFor管道以通過對象屬性過濾對象數組?
一個用於Leagues
,一個用於Divisions
我想創建一個Pipe
將取決於選擇什麼League
過濾Divisions
。
給出下面的數據。如果我選擇Random Beer League
只有TwoFour
和SixPack
應該顯示爲Divisions
選擇的選項。
leagues = [
{id: 1, leagueName: 'Recreation League' },
{id: 2, leagueName: 'Random Beer League' }
];
divisions = [
{id: 1, divisionName: 'SoGreen', leagueId: 1, leagueName: 'Recreation League' },
{id: 2, divisionName: 'Yellow', leagueId: 1, leagueName: 'Recreation League' },
{id: 3, divisionName: 'TwoFour', leagueId: 2, leagueName: 'Random Beer League' },
{id: 4, divisionName: 'SixPack', leagueId: 2, leagueName: 'Random Beer League' }
];
*注 - 數據plunker是硬編碼,但在我的應用程序設置了觀測。
我已經更新plnkr鏈接。原因是angular2將「ngOnChange」事件重命名爲「onChange」。 –