Generic type 'Array<T>' requires 1 type argument(s). - Angular2

Gayathri picture Gayathri · Jul 1, 2017 · Viewed 24.8k times · Source

I have been trying to implement a simple ngFor with Angular2 but I don't know what went wrong which lead to error 'Generic TYpe Array requires one argument(s). PLease favour

import { Component } from '@angular/core';


    @Component({
        selector: 'my-app',
        templateUrl:'./app.component.html',                     
    })
    export class AppComponent { 
           clients:Array;
           doctors:Array;
            constructor(){
               this.clients=["Client1", "Client2", "Client3"];
                this.doctors=["Doctor1","Doctor2","Doctor3"];
            }


    }

Answer

manideep pabba picture manideep pabba · Jul 24, 2017

solution 1:

clients: String[]; // if type cant be determined use 'any[]'
    doctors: String[];

solution 2:

clients: Array<String>; // if type cant be determined use '<any>'
    doctors: Array<String>;