1

JSON

{
    "bloodGroup":[
      {"Id":1, "Value":"O +ve", "Description":"OPositive"}, 
      {"Id":2, "Value":"O -ve", "Description":"ONegative"}, 
      {"Id":3, "Value":"AB +ve", "Description":"ABPositive"}
    ],
    "Gender":[
      {"Id":1, "Value":"Male", "Description":"Male"}, 
      {"Id":2, "Value":"Female", "Description":"Female"}
    ]
}

Pipe:

  transform(aList: Lookup[], lookUpName: string): Lookup[] {
    if (!aList || !lookUpName || aList.length === 0) {
        return aList;
    }

  return Array.of(aList[lookUpName])
}

Lookup Class (autogenerated from nswag):

export interface ILookup {
    name?: string | undefined;
    value?: string | undefined;
    description?: string | undefined;
}

HTML:

  <option *ngFor="let gender of aList | lookupFilter:'Gender'" [value]="gender.Id">
              {{gender.Value}}
  </option>

The select doesn't bind the required values. What am i doing wrong?

5
  • i think the issue is with Pipe. can you update question with complete pipe class Commented Jul 20, 2019 at 4:11
  • is it needed to use lookupFilter. cannot it used as <option *ngFor="let gender of aList.Gender" [value]="gender.Id">{{gender.Value}}</option> Commented Jul 20, 2019 at 4:14
  • Seems a good option, didn't think of it as it was a different scenaio before so i was using the filterPipe. Will give it a try @SudarshanaDayananda Commented Jul 20, 2019 at 4:20
  • Worked just like that, thank you @SudarshanaDayananda Still i'm curious why didn't this work. Anyways will use the method u proposed. Commented Jul 20, 2019 at 4:22
  • check my answer. Commented Jul 20, 2019 at 4:26

1 Answer 1

1

Change Array.of(aList[lookUpName]) to aList[lookUpName]. Everything will work fine.

 transform(aList: Lookup[], lookUpName: string): Lookup[] {

    if (!aList || !lookUpName || aList.length === 0) {
        return aList;
    }
    return aList[lookUpName];
}

StackBlitz.

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

1 Comment

I was trying to convert JSON to array to bind the values to select, so select works directly with json which i don't know. Thanks again. Will mark your name for my future work, please help out.

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.