简体   繁体   中英

How to reset input value in angular 2

I want to reset the search text field after i hit enter,close or 'x' button.As per my code it clears the characters after closing the window but when i open it again it doesn't display list of user names until i hit backspace on search field. Any solutions

code:

export class child extends parent {
        private findSubject = new Subject();
        constructor() {
            this.init();
            this.findtream = this.findSubject.debounceTime(300);
        }
    }


<button type="button" (click)="close();findName.value=''" style="cursor: pointer; position: absolute; top: 18px;" [style.left.px]="functionalityActive === 0 ? 723 : 668"><span aria-hidden="true " style="font-size: 37px;">x</span></button>
<input type="text" #findName  class="search-text" (keyup)="findSubject.next(findName.value)">
<button type="button" class="btn btn-danger event-buttons" id="create-button"(click)="close();findName.value=''">Close</button>

您可以尝试将window.onload()getElementById结合以在窗口重新加载时设置其值

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM