angular - 角度业力测试 indefined id
问题描述
我正在尝试测试父子组件,父测试成功但我在 oninit 中调用@output 属性的子组件失败“无法读取未定义的属性'id'”
export class SinglepostComponent implements OnInit {
@Input() post: Post;
@Input() posts: Array<Post>;
public comments: Array<Comment>;
public comm: Comment;
constructor(
private postService: PostService,
private dataService: DataService,
public dialog: MatDialog,
public commentservice: CommentService
) { }
ngOnInit() {
this.postService.getComments(this.post.id).subscribe(data => {
this.comments = data;
});
}
解决方案
推荐阅读
- asp.net-core - Hangfire 后台作业创建失败并出现 InvalidCastException
- html - 如何在 Sublime Text 3 中自定义 Emmet 缩写
- php - 如何安排通知
- ios - Swift 包管理器:如何像在常规 Xcode 项目中一样加载 UIViewController + xib 对?
- c++ - memory_order_relaxed 和可见性
- python - 熊猫 groupby.sum() 无法正常工作?
- c++ - 使用makefile控制c++程序的输出
- firebase - 使用 firebaseAuthemication 与 google 登录时出错
- javascript - 在 javascript 中从 Button-Group 中检索数据
- r - 用 ggplot2 复制 BGVAR 图