9 changed files with 102 additions and 80 deletions
@ -1,4 +1,3 @@
|
||||
<div class="content" [ngStyle]="{'left': leftCss,'top': topCss,'min-width': minWidthCss}" *ngIf="searchList.length"> |
||||
<h1>I'm loaded</h1> |
||||
<div *ngFor="let item of searchList" (click)="select(item)" class="item">{{item.name}}</div> |
||||
</div> |
@ -1,55 +1,53 @@
|
||||
import { Component, OnInit, Inject } from '@angular/core'; |
||||
import { AutocompleteSelect } from '../../map'; |
||||
|
||||
import { AutocompleteSelect, HtmlRender } from '../../map'; |
||||
|
||||
type ClickHandler = (data: AutocompleteSelect) => void; |
||||
|
||||
@Component({ |
||||
selector: 'SearchDownList', |
||||
templateUrl: './SearchDownList.html', |
||||
styleUrls: ['./SearchDownList.scss'] |
||||
}) |
||||
export class SearchDownList implements OnInit { |
||||
private $input; |
||||
constructor() { |
||||
} |
||||
constructor() {} |
||||
|
||||
public $input; //input
|
||||
public searchList: AutocompleteSelect[] = []; //list
|
||||
public leftCss: string = '0px'; |
||||
public topCss: string = '0px'; |
||||
public minWidthCss: string = '0px'; |
||||
private clickHandler: ClickHandler; |
||||
|
||||
ngOnInit(): void { |
||||
window.onresize = () => { |
||||
if (this.$input) { |
||||
let Dom = this.$input.getBoundingClientRect() |
||||
this.leftCss = `${Dom.left + 3}px` |
||||
this.topCss = `${Dom.top + Dom.height + 3}px` |
||||
this.minWidthCss = `${Dom.width}px` |
||||
} |
||||
} |
||||
} |
||||
|
||||
setClickHander(handler: ClickHandler) { |
||||
this.clickHandler = handler; |
||||
} |
||||
|
||||
clearClickHander() { |
||||
this.clearClickHander = null; |
||||
} |
||||
init(elementId: string): void { |
||||
this.$input = document.getElementById(elementId); |
||||
//this.addDOMEvent();
|
||||
} |
||||
// input 添加监听事件
|
||||
addDOMEvent() { |
||||
|
||||
// this.left = DOM.left
|
||||
// this.top = DOM.top + DOM.height + 2
|
||||
// this.minWidth = DOM.width
|
||||
init(inputElement: HtmlRender): void { |
||||
this.$input = inputElement |
||||
let Dom = this.$input.getBoundingClientRect() |
||||
this.leftCss = `${Dom.left + 3}px` |
||||
this.topCss = `${Dom.top + Dom.height + 3}px` |
||||
this.minWidthCss = `${Dom.width}px` |
||||
} |
||||
|
||||
// 触发 select
|
||||
select(e) { |
||||
this.clearClickHander && this.clickHandler(e); |
||||
this.searchList = []; |
||||
} |
||||
|
||||
watch() { |
||||
//TODO:修改leftCss ,topCss
|
||||
} |
||||
|
||||
testAddData() { |
||||
this.searchList.push({ |
||||
name: "asfasdfasdf" |
||||
} as AutocompleteSelect); |
||||
} |
||||
} |
Loading…
Reference in new issue