简体   繁体   English

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

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

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). 我一直在尝试使用Angular2实现一个简单的ngFor,但我不知道导致错误的错误'Generic TYpe Array需要一个参数。 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"];
            }


    }

solution 1: 解决方案1:

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

solution 2: 解决方案2:

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

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

NOTE: what you could do is replace String with the angular2 typename for a string primitive. 注意:您可以做的是用字符串基元的angular2 typename替换String

暂无
暂无

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

相关问题 @ angular / forms通用类型&#39;类型 <T> &#39;需要1种类型的参数 - @angular/forms Generic type 'Type<T>' requires 1 type argument(s) 通用类型主题<t>需要 1 个类型参数。 - Angular</t> - Generic type Subject<T> requires 1 type argument(s). - Angular Angular 错误 - 通用类型“ModuleWithProviders”<t> ' 需要 1 个类型参数</t> - Angular error - Generic type 'ModuleWithProviders<T>' requires 1 type argument(s) “如何修复‘错误:(5, 12) TS2314:通用类型‘数组<T> &#39;在 Angular 中需要 1 个类型参数&#39; - "How to fix 'Error:(5, 12) TS2314: Generic type 'Array<T>' requires 1 type argument(s) ' in Angular" Angular 9 Ivy - 通用类型 'ɵɵFactoryDef' 需要 2 个类型参数 - Angular 9 Ivy - Generic type 'ɵɵFactoryDef' requires 2 type argument(s) Angular 10 Swagger 代码生成:通用类型 ModuleWithProviders<t> 需要 1 个类型参数</t> - Angular 10 Swagger Codegen: Generic type ModuleWithProviders<T> requires 1 type argument(s) opentok angular 6 错误 TS2314:通用类型 &#39;Promise<T> &#39; 需要 1 个类型参数 - opentok angular 6 error TS2314: Generic type 'Promise<T>' requires 1 type argument(s) JWT 库错误:通用类型 'ModuleWithProviders<t> ' 在 Angular 10 中需要 1 个类型参数</t> - JWT library error: Generic type 'ModuleWithProviders<T>' requires 1 type argument(s) in Angular 10 Angular 5升级错误:通用类型&#39;InjectionToken <T> &#39;需要1种类型的参数 - Angular 5 Upgrade Error: Generic type 'InjectionToken<T>' requires 1 type argument(s) Angular 11 通用类型'HttpRequest<t> ' 需要 1 个类型的参数。ts(2314)</t> - Angular 11 Generic type 'HttpRequest<T>' requires 1 type argument(s).ts(2314)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM