-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在区组件的局部变量。