import { Subscription } from "rxjs";
@Component({
selector: 'app-listing-detail',
templateUrl: './listing-detail.component.html',
styleUrls: ['./listing-detail.component.scss']
})
export class ListingDetailComponent implements OnInit {
id: string;
listing!: Listing | undefined;
listingSub$: Subscription | undefined;
thisid: string | undefined;
constructor(private listingService: ListingService, private route: ActivatedRoute) {}
ngOnInit() {
this.id = this.route.snapshot.paramMap.get("id");
this.listingSub$ = this.listingService.getListing(this.id).subscribe(listing => {
this.listing = listing;
});
}
}
答案 0 :(得分:0)
错误包含答案。您需要该属性始终具有值。解决方案是默认分配 listingSub$ = undefined
。
export class ListingDetailComponent implements OnInit {
...
listingSub$: Subscription | undefined = undefined;
...
}