Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 无法以角度指定数据源值_Angular_Material Design_Angular Material - Fatal编程技术网

Angular 无法以角度指定数据源值

Angular 无法以角度指定数据源值,angular,material-design,angular-material,Angular,Material Design,Angular Material,构造函数(私有appService:appService){} 新英雄:putDetail 数据源:MatTableDataSource; 恩戈尼尼特(){ this.appService.getComplaints() .subscribe(data=>this.newHero=data); this.dataSource=this.newHero; } 错误: 类型“putDetail”不可分配给类型 “MatTableDataSource”。类型中缺少属性“\u data” “细节”。(属

构造函数(私有appService:appService){} 新英雄:putDetail 数据源:MatTableDataSource; 恩戈尼尼特(){ this.appService.getComplaints() .subscribe(data=>this.newHero=data); this.dataSource=this.newHero; } 错误:

类型“putDetail”不可分配给类型 “MatTableDataSource”。类型中缺少属性“\u data” “细节”。(属性)ComplaintsComponent.dataSource: MatTableDataSource


您需要初始化
dataSource
并使用
this.dataSource.data
而不是
this.dataSource
,并将其放入
subscribe
回调中,以确保仅在解决订阅时才填充它

http
得到的响应不是JSON数组,而是JSON对象。使用将响应转换为数组

constructor(private appService: AppService) { }
          newHero:putDetail
         dataSource = new MatTableDataSource<putDetail>();
          ngOnInit() {
          this.appService.getcomplains()
          .subscribe(data{ => this.newHero = data;
            this.dataSource.data = Object.values(this.newHero);


        });

      }
构造函数(私有appService:appService){}
新英雄:putDetail
dataSource=新MatTableDataSource();
恩戈尼尼特(){
this.appService.getComplaints()
.subscribe(数据{=>this.newHero=data;
this.dataSource.data=Object.values(this.newHero);
});
}

我仍然收到相同的错误,类型“putDetail”不可分配给类型“putDetail[]”。类型“putDetail”中缺少属性“includes”。如果此操作无效,是否共享您的服务代码?您的服务是否返回对象数组?服务代码:getcomplains():Observable{返回this.http.get(');}更新了我的回答是的,我添加了快照,请检查