the component i have is an autocompleter. however it is located inside a fixed height div and the results div needs to be parented to the body and positioned to display correctly. What would be the proper way to do this in angular2?
@Component({
selector: 'autocomplete',
template: `
<div class="container" >
<div>
<input id="search" type="text" class="validate filter-input" [(ngModel)]=query (keyup)="filter()">
</div>
<div *ngIf="filteredList.length > 0">
<ul *ngFor="let item of filteredList" >
<li >
<a (click)="select(item)">{{item}}</a>
</li>
</ul>
</div>
</div>`,
})
export class AutocompleteComponent {
private items: string[];
public query: string;
public filteredList: string[];
public elementRef: ElementRef;
constructor(element: ElementRef) {
this.items = ['foo', 'bar', 'baz'];
this.filteredList = [];
this.query = '';
this.elementRef = element;
}
filter() {
if (this.query !== '') {
this.filteredList = this.items.filter(function(item) {
return item.toLowerCase().indexOf(this.query.toLowerCase()) > -1;
}.bind(this));
}
else {
this.filteredList = [];
}
}
}