【发布时间】:2018-01-11 14:43:44
【问题描述】:
在我的应用程序中,我有一个组件将用户对象发送到另一个组件,并且它正确地接收到它,正如成功的 console.log(user.vendorname) 按预期返回所证明的那样,但它不会显示在 html 上。 html文件
<div class="col-centered">
<h1 *ngIf="user | async">Welcome {{user.vendorname}}</h1>
</div>
组件文件
import { User } from '../User';
import { AccountInfo } from './../AccountInfo';
import { LoginService } from './../login.service';
import { Component, OnInit, AfterViewInit, OnDestroy } from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import { Subscription } from 'rxjs/Subscription';
import 'rxjs/add/operator/map';
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.css']
})
export class DashboardComponent implements OnInit {
user: User;
subscription: Subscription;
constructor(route: ActivatedRoute, private loginService: LoginService) {
}
ngOnInit() {
this.subscription = this.loginService.getMessage().subscribe(data => {
this.user = data;
console.log(this.user.vendorname);
});
}
AfterViewInit(){
}
ngOnDestroy() {
// unsubscribe to ensure no memory leaks
}
}
【问题讨论】:
标签: angular angular2-template angular2-services angular2-directives