【发布时间】:2017-06-26 15:56:15
【问题描述】:
我创建了一个user photo component,它接受一个@Input() 值,这个值就是userId。如果传入了该值,则我从链接到此 userId 的 Firebase 检索信息,如果没有,则执行其他操作。
我的用户照片组件
import { Component, OnInit, OnDestroy, Input } from '@angular/core';
@Component({
selector: 'user-photos',
templateUrl: './user-photos.component.html',
styleUrls: ['./user-photos.component.css']
})
export class UserPhotoComponent implements OnInit {
@Input() userId: string;
constructor() {
console.log('userId is:',this.userId);
}
ngOnInit() {
}
ngOnDestroy() {
}
}
如您所见,我已将 userId 声明为 @Input(),现在在我的 edit-profile component 上我有以下内容:
<user-photos [userId]="TestingInput"></user-photos>
现在,当我看到 h1 标记出现时,User Photo 组件被渲染,但是 userId 始终未定义?
开发者控制台中没有出现任何错误,所以我不完全确定我做错了什么。
【问题讨论】:
标签: angular typescript