Angular Compnent-类型'(数据:任何)=>任何'缺少以下类型的属性

时间:2019-06-09 22:48:08

标签: angular laravel

我有Angular Frontend和Laravel Endpoint。在我的Angular中,我有模型,服务。尝试运行代码时,出现此错误。

  

(属性)PremiumSmsProductListComponent.products:Cloudsubscriptions []   类型((data:any)=> any)缺少类型'Cloudsubscriptions []'中的以下属性:data,success,pop,push和27 more.ts(2740)

import { Component, OnInit } from '@angular/core';
import { CloudsubscriptionsService } from '../../../services/cloudsubscriptions.service';
import Cloudsubscriptions from '../../../models/cloudsubscriptions';

@Component({
  selector: 'app-premium-sms-product-list',
  templateUrl: './premium-sms-product-list.component.html',
  styleUrls: ['./premium-sms-product-list.component.scss']
})
 export class PremiumSmsProductListComponent implements OnInit {

  isLoadingResults = true;    

  products: Cloudsubscriptions[];
  constructor(private bs: CloudsubscriptionsService) { }
  deleteCloudsubscription(id) {
this.bs.deleteCloudsubscription(id).subscribe(res => {
  console.log('Deleted');
});
  }

  ngOnInit() {

this.bs
.getCloudsubscription()
.subscribe((data: Cloudsubscriptions[]) => {
  console.log(data.data);
  if(data.success==true)
  {
    this.products = data.data;
  }

  });

模型:cloudsubscriptions.ts

export default class Cloudsubscriptions {
 public msisdn: string;
 public is_subscribe: number;
 public package_id: number;
 public transaction_id: string;
 public platform_transaction_id: number;
 public status: string;
 public amount: string;
 public transaction_type: string;
 public channel: string;
 public service_name: string;
}

所以,我遇到了这个错误

subscription

enter image description here

我该如何解决

1 个答案:

答案 0 :(得分:3)

好像订阅返回了一个Cloudsubscriptions数组。

如果这是真的,那应该可行

this.products = data;

您的代码似乎假设data是具有以下结构的对象。


data = {
   data : CloudSubscriptions[]
   success: Boolean
}

尝试使用console.log(data.data);而不是console.log(data)来查看订阅实际返回的内容。