angular - Angular2 dropdown component scroll into view -


how scroll view selected element of dropdown box? got stuck issue. angular2 pattern bellow have no reference html li tag. scroll slider should move after entry field selected , feed down arrow key. should best practice? has solution, please?

    import { bootstrap } 'angular2/platform/browser';     import { component, view } 'angular2/core';     import { ngfor, form_directives, ngclass } 'angular2/common';      export class model {         constructor(public itemid: number, public value: string, public isfocused: boolean) { }     }      @component({selector: "app"})     @view({template: `         <style>             .drmenu {position: absolute; z-index: 1000; min-width: 250px; background-color: #fff;                 border: 1px solid rgba(0,0,0,.15); max-height: 60px; overflow-x: hidden;}              .itembackground {background-color: red;}             .selecteditembackground {background-color: green;}        </style>          <div style="position: relative;">             <input (keydown)="onkeydown($event)"/>             <ul class="drmenu">                 <li *ngfor="#item of items">                     <div [ngclass]="{itembackground: item.isfocused, selecteditembackground: !item.isfocused}">{{item.value}}</div>                             </li>             </ul>         </div>         `,         directives: [ngclass, ngfor]     })     class appcomponent {         items: array<model> = [new model(1, "i1", false), new model(1, "i2", false), new model(1, "i3", false), new model(1, "i4", false), new model(1, "i5", false), new model(1, "i6", false)];          private onkeydown(event: keyboardevent) {             var keycode = event.which || event.keycode;             var focusedindex = this.items.findindex(i => i.isfocused);             switch (keycode) {                 case 38:                     if (focusedindex > 0) {                     this.items[focusedindex].isfocused = false;                         this.items[focusedindex - 1].isfocused = true;                     }                     break;                 case 40:                     if (focusedindex < this.items.length) {                         if (focusedindex > -1) { this.items[focusedindex].isfocused = false; }                         this.items[focusedindex + 1].isfocused = true; }                     break;             }         }     }     bootstrap(appcomponent); 

i solved implementing directive , mapping <li> reference model:

    <li *ngfor="#item of items" [diritemid]=item.itemid (elementcreated)="elementcreated($event)"> 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -