我有一张表格,我用一个嫌疑人来控制改变:
<form #f="ngForm">
<mat-card-content>
<mat-input-container>
<input matInput [(ngModel)]="id" name="id" placeholder="id" (ngModelChange)="elementChanged$.next($event)"/>
</mat-input-container>
</mat-card-content>
</form>
export class myComponent implements OnInit {
dataToGet: string;
formChanged$: Observable<boolean>;
elementChanged$: Subject<any> = new Subject<any>();
elementSubscription: Subscription;
constructor() {
this.elementSubscription = this.elementChanged$
.debounceTime(500)
.map(this.formHaveChanged)
.subscribe(haveChanged => this.formChanged$ = haveChanged)
}
formHaveChanged(): Observable<boolean> {
this.dataToGet -> fails because of this is mapSuscriber
return Observable.of(true)
}
}
所以我的问题很清楚,当我在formHaveChanged()函数中“这个”是mapSuscriber而不是myComponent时,我需要访问mycomponent变量,但是我无法得到它,我怎么能这样做?
答案 0 :(得分:1)
.map(() => this.formHaveChanged())
或
this.formHaveChanged
{{1}}是未绑定的功能。您无法在未绑定的函数中访问它。