这是一个简单的问题并且已经完成了很多次,但现在我无法创建一个对象数组。我自然地用谷歌搜索,下面也是他们所拥有的。
@Injectable()
export class SearchService {
private let data: User[] = [
{ssn: "146-89-5656", userId: 'jochampa', office: 'AMB', role: 'admin'},
{ssn: "777-88-1000", userId: 'teddyBear', office: 'AMB', role: 'admin'},
{ssn: "132-40-4000", userId: 'Josh', office: 'AMB', role: 'admin'},
{ssn: "123-56-6000", userId: 'Kori', office: 'AMB', role: 'admin'},
{ssn: "777-98-7000", userId: 'Dummy', office: 'AMB', role: 'admin'},
{ssn: "899-19-2200", userId: 'Drew', office: 'AMB', role: 'admin'},
{ssn: "021-69-2222", userId: 'Ken', office: 'AMB', role: 'admin'},
{ssn: "589-47-9999", userId: 'Justin', office: 'AMB', role: 'admin'},
{ssn: "146-89-5656", userId: 'jochampa', office: 'AMB', role: 'admin'},
{ssn: "777-88-1000", userId: 'teddyBear', office: 'AMB', role: 'admin'},
{ssn: "132-40-4000", userId: 'Josh', office: 'AMB', role: 'admin'},
{ssn: "123-56-6000", userId: 'Kori', office: 'AMB', role: 'admin'},
{ssn: "777-98-7000", userId: 'Dummy', office: 'AMB', role: 'admin'},
{ssn: "899-19-2200", userId: 'Drew', office: 'AMB', role: 'admin'},
{ssn: "021-69-2222", userId: 'Ken', office: 'AMB', role: 'admin'},
{ssn: "589-47-9999", userId: 'Justin', office: 'AMB', role: 'admin'},
];
但是当我将鼠标悬停在ERROR TS1005 expected =
用户对象:
export class User {
ssn:string;
userId:string;
lastName:string;
office:string;
role:string;
}
答案 0 :(得分:2)
我不认为这是写这个private let data: User[] =..
的正确方法
这是一个字段还是一个局部变量?
如果它是一个字段,那么它应该是
private data: User[] = ..
因此,您可以使用this.data
否则它应位于contstructor
方法内或@Injectable
此外,对象不具有lastName
属性。