我创建了一个具有属性的组件,该属性在ngOnInit
上初始化:
@Component({
//...
})
export class Validate implements OnInit, OnDestroy {
private user: UserDTO;
constructor(private router: Router, private route: ActivatedRoute, private userService: UsersService) {}
ngOnInit():void {
this.sub = this.route.queryParams.subscribe(params => {
if (this.id != undefined && this.token != undefined)
this.userService.get("id")
.subscribe(
(result: UserDTO) => {
this.user = result;
}
)
else
this.router.navigate(['/error']);
});
}
//...
}
UserDTO.ts:
export interface UserDTO {
id?: string;
username?: string;
cname?: string;
sname?: string;
mail?: string;
}
在我的模板上,我写的user.cname
显示在标记内:
<header>
<h3>Hi {{user.cname}}!!!</h3>
</header>
尽管如此,<h3> tag
内没有显示任何内容。
有什么想法吗?