0

when i try to bind name using method in *ngFor loop, infinite loop is running on my angular 6 project.why is that happening? and please recommend a solution. thank you...

<div *ngFor="let menu of MenuList"> 
     <span>{{bindMenuNames(menu.FullNameSpace)}}</span> 
  </div>

 bindMenuNames(FullNameSpace): string 
  {
        console.log(FullNameSpace);
        let menuname: string;
        switch (FullNameSpace)
        {
            case "Message_Centrel":
                menuname = "Messaging";
                break;

            case "Admin":
                menuname = "Admin"
                break;
            case "Catalog":
                menuname = "Course Authoring"
                break;
           default:
                menuname = ""
                break;
        }
       return menuname;
    }

please see following image

2
  • Code looks good to me, Can you check MenuList length? Commented Apr 17, 2019 at 12:03
  • yes you can use this line to check length of menulist >>> *ngIf="MenuList ?.length > 0" <<< Commented Apr 18, 2019 at 6:58

1 Answer 1

1

at ts file:

public obj = {'Message_Centrel': 'Messaging', 'Admin': 'Admin', 'Catalog': 
             'Course Authoring'}

at html file:

<div *ngFor="let menu of MenuList"> 
 <span>{{obj[menu.FullNameSpace] ? obj[menu.FullNameSpace] : '-'}}</span> 
</div>
Sign up to request clarification or add additional context in comments.

Comments

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.