Samy
Samy

Reputation: 1033

Array with Objects

I started learning AngularJS but had a little problem.... What is wrong here ? I try to declare songlist as an array with Song Objects but get an error to use "="

import { Song } from './song.model';

export class Chart
{
  id:number;
  chartName: string;
  img: string;
  createDate:string;

  songList[]: Song;

}

Upvotes: 1

Views: 102

Answers (2)

LLai
LLai

Reputation: 13396

Check out this typescript type definition for arrays.

https://www.typescriptlang.org/docs/handbook/basic-types.html

The syntax for typescript typecasting is

variable: type;

So for an array you'll want something like

songList: Array<Song>;

or

songList: Song[];

Upvotes: 2

ms87
ms87

Reputation: 17492

Your declartion is invalid, should be:

songList: Song[]

Upvotes: 2

Related Questions