繁体   English   中英

通用类型“Array <T>”需要1个类型的参数。 - Angular2

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

我一直在尝试使用Angular2实现一个简单的ngFor,但我不知道导致错误的错误'Generic TYpe Array需要一个参数。 喜欢

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


    }

解决方案1:

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

解决方案2:

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

我没有使用过Angular2,但我相信解决方案,因为你知道数组将要保存的类型,就是使用Array<String>而不是数组。

注意:您可以做的是用字符串基元的angular2 typename替换String

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM