当我在我的 html{{user.firstName}}
中使用它时,数据显示但有错误,但是当我在我的 html{{user?.firstName}}
中使用它时,数据没有显示但没有错误,但是当我单击按钮时,数据正在显示。大家好,我正在使用 metronic 和 angular8
你有关于如何显示数据的替代人吗?
import { Component, OnInit, enableProdMode } from "@angular/core";
import { DealerapiService } from "../services/dealerapi.service";
import { DomSanitizer } from "@angular/platform-browser";
import { FormGroup, FormBuilder } from "@angular/forms";
import { ActivatedRoute } from "@angular/router";
@Component({
selector: "kt-home-profile",
templateUrl: "./home-profile.component.html",
styleUrls: ["./home-profile.component.scss"]
})
export class HomeProfileComponent implements OnInit {
constructor(
private dealerApiService: DealerapiService,
private domSanitizer: DomSanitizer,
private formBuilder: FormBuilder,
private route: ActivatedRoute
) {}
forms: any;
profileForm: FormGroup;
imageurl: any;
username: any;
user: any;
ngOnInit() {
this.route.params.subscribe(params => {
// get the username out of the route params
this.username = params["username"];
const username = params["username"];
this.dealerApiService
.getUserbyUsernameProfile(username)
.subscribe((user: any) => {
this.user = user.data;
console.log(user);
});
});
}
}