1

This is a simple question and have done this many time but now I am unable to make an array of objects. I naturally googled and the below is what they had too.

@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'},
    ];

But I get an error when I hover over it saying ERROR TS1005 expected =

User object:

export class User {
    ssn:string;
    userId:string;
    lastName:string;
    office:string;
    role:string;
}

enter image description here

1
  • You should not use let for assignment and you are missing lastName in the User object. You can make lastName optional by defining it as lastName?:string Commented Feb 17, 2017 at 20:01

1 Answer 1

2

I don't think this is the right way to write this private let data: User[] =.. Is this a field or a local variable?

If it's a field then it should be

private data: User[] = ..

So you can access it in your class with this.data

else it should be inside a contstructor, method or outside of the @Injectable

Also the objects don't have the lastName property.

Sign up to request clarification or add additional context in comments.

3 Comments

I tried that too, please see the picture I just added.
@Drew1208 Is it the same error? Did you compile the ts? Also the objects don't have the lastName property
It was the lastName. I need to step away for a while.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.