reza setareh
reza setareh

Reputation: 75

problem in defining empty list of a class in angular 12

i have a problem defining a empty list of a class in angular.this is my class

export class category{
public Id:number;
public Name:string;
constructor(
){}}

enter image description here

i got this error.

An element access expression should take an argument

any help will be highly appreciated

Upvotes: -1

Views: 702

Answers (1)

Merna Mustafa
Merna Mustafa

Reputation: 1373

You got this error because you are trying to declare your variable after import statements, not into the class.
You should declare it as below:

//import statements
@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.css"],
})
export class AppComponent {
  category: category[] = [];
  constructor() {}

  ngOnInit() {}
}

Upvotes: 1

Related Questions