带有 angular 4 中方法调用的异步管道无限调用

Mah*_*Gvp 5 angular-bootstrap bootstrap-4 angular-pipe angular

我需要提供带有动态选项的 select UI 元素,我有一个方法可以根据 Inputs 返回一个 observable

TypeScript(组件类)

getCars(type : string, engine : string) : Observable<Cars>{
    return this.carService.getCars(type,engine);
} 
Run Code Online (Sandbox Code Playgroud)

在 HTML 中,我让我的元素为数据调用此方法

Html(模板文件)

<ng-select [items]="getCars(type,engine) | async"
    bindLabel="value"
    bindValue="id"
</ng-select>
Run Code Online (Sandbox Code Playgroud)

但这会导致服务被无限调用。我不想使用 ngOnInit 因为我需要动态分配 observable

我正在使用此 UI 元素进行选择

Fat*_*med 4

这是预期的行为,以及角度变化检测的工作原理,从视图调用方法并使用属性代替不是一个好主意

this.cars = getCars(type,engine)
Run Code Online (Sandbox Code Playgroud)