1

In my component created the variable with the of any[], as per my requirement dynamic value will come from service based on that variable has to create and assign the value.

export class CostsComponent implements OnInit {

  public info: any[] = [];
  constructor(private deliverablesService: DeliverablesService, private setupcostsService: SetupcostsService, private activatedRoute: ActivatedRoute) { }

  ngOnInit() {
    this.activatedRoute.params.subscribe((params: Params) => {
      this.setupcostsService.getcostDetails(2940).subscribe(
        data => {
          this.info.col = data.col; // dynamic
          this.info.data = data.data; //dynamic
          console.log('cost Info',data);
        },
        () => { }
      );

    });
  }

while setting this.info.col getting the Property 'col' does not exist on type 'any[]'. error.

Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234
Govinda raj
  • 613
  • 3
  • 16
  • 31

1 Answers1

2

You are initialize the variable as an array, you can't read an array property without using index. So you should define that variable as an object instead of array.

Try public info: any = {}; instead of public info: any[] = [];

I hope this below discussion may help you.

What is the difference between any and any[ ]?

Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234