Holiday Notice: Support will be provided on a limited scale from December 24th, 2024, to January 2nd, 2025. Happy holidays and a wonderful New Year!


Topic: Dropdown load selected item

kjimenezdev pro asked 7 years ago


Hi, is there a way to load items on mdb dropdown component using angular 4 and set one item as the currently selected one?

Dawid Adach pro answered 7 years ago


Dear kijmenezdev,

Sure, you can easily do that:

 

component.html:

<div class="btn-group" dropdown>

<buttondropdownToggletype="button"class="btn btn-primary dropdown-toggle waves-light"mdbRippleRadius>

Basic dropdown

</button>

<divclass="dropdown-menu dropdown-primary">

<li role="menuitem" *ngFor="let link of links"><a class="dropdown-item" [class.active]="link.isActive"href="{{link.url}}">{{link.name}}</a></li>

</div>

</div>

Component.ts:

links= [

{id: 1, name: 'Google', url: 'http://google.com', isActive: false},

{id: 2, name: 'Microsfot', url: 'http://microsoft.com', isActive: false},

{id: 3, name: 'Facebook', url: 'http://facebook.com', isActive: true},

{id: 4, name: 'Yahoo', url: 'http://yahoo.com', isActive: false},

];


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Pro
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No
Tags