[英]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.