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.

1 Answer 1

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[ ]?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.