最佳答案
                                        
                                                                        
                                我已经创建了一个 user photo component,它接受一个 @Input()值,这个值是 userId。如果该值被传入,那么我将从 Firebase中检索链接到这个 userId 的信息,如果没有,那么我将执行其他操作。
我的用户照片组件
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标签出现时,用户照片组件得到呈现,但是 userId 总是未定义?
在开发人员控制台中没有出现错误,所以我不能完全确定我做错了什么。
 
                                
                             
                                
                             
                                
                             
                                
                             
                                
                             
                                
                             
                                
                             
                                
                             
                                
                            