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

2

17

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"];
            }


    }
Remission answered 1/7, 2017 at 19:25 Comment(1)
Read Generics Concept in programming firstPetulancy
H
39

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>;
Homeric answered 24/7, 2017 at 14:35 Comment(0)
H
1

I have not used Angular2, but I believe the solution, since you know the type which the array is going to hold, is to use Array<String> instead of array on its own.

NOTE: what you could do is replace String with the angular2 typename for a string primitive.

Heartwood answered 1/7, 2017 at 19:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.