angular2 ngFor not working while fetching data from api on ngOnInit()

后端 未结 6 472
别跟我提以往
别跟我提以往 2021-01-13 03:42

comment.component.ts:

import { Component, OnInit } from \'@angular/core\';
import { Router} from \'@angular/router\'
import { Comment } from         


        
6条回答
  •  抹茶落季
    2021-01-13 04:49

    Try this
    template:

    • {{comment.Name}}

    comments: Observable;  
        ngOnInit() {      
           this.comments = this.getComments();
        }
    
        getComments() {      
         return this.commentService.getComments();   
       }
    

    I see 2 problems in your code 1. You call map without returning any value. 2. You try to set values inside map instead of subscribe but the values was undefined once it reach subscribe in your ngOnInit

提交回复
热议问题