-1
我有2個分離的組件CityComponent和DistrictComponent。在CityComponent中我有城市列表,我怎麼能得到DistrictComponent中的城市數據來使用* ngFor作爲選擇標籤?如何從角度2中的其他組件獲取數據?
我有2個分離的組件CityComponent和DistrictComponent。在CityComponent中我有城市列表,我怎麼能得到DistrictComponent中的城市數據來使用* ngFor作爲選擇標籤?如何從角度2中的其他組件獲取數據?
您可以使用@input進行此類處理。
假設不同的組件有一些關鍵過濾城市組件的城市。
你可以參考以下:
第1步:
區組件作爲綁定:
<district-component-selector [cityListInput]="cityList"></district-component-selector>
其中, cityList持有組件的城市完整列表。
步驟2:
在區組件,你可以參考它:
import { Input } from "@angular/core";
@Input() set cityListInput(value: String[]) {
this.cityList= value;
}
其中, cityList在區組件的局部變量。