角因果检验未定义ID

时间:2018-09-05 12:23:58

标签: angular karma-runner

我正在尝试测试父级子组件,父级测试成功,但是我在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;
           });
             } 

0 个答案:

没有答案