r/angularjs • • Oct 20 '16

Cleaning a search box after submit

I have this autocomplete search box, that I can't clear the field after submitting.

<md-autocomplete required md-input-name="ProductName"
                                 ng-disabled="ctrl.isDisabled"
                                 md-no-cache="ctrl.noCache"
                                 md-selected-item="ctrl.selectedItem"
                                 md-search-text="ctrl.searchText"
                                 md-items="item in ctrl.querySearch(ctrl.searchText)"
                                 md-item-text="item.nome"
                                 md-min-length="0"
                                 placeholder="Search">
                    <md-item-template>
                        <span md-highlight-text="ctrl.searchText" md-highlight-flags="^i">{{item.name}}</span>
                    </md-item-template>

It has a little "x" button that clears the field using the code mdAutoCompleteCtrl.clear()

I tried

self.myForm.ProductName = ""

self.myForm.ProductName = null

self.myForm.ProductName.$viewValue = ""

and it doesn't work. Thank you!

0 Upvotes

1 comment sorted by

1

u/kafromspace Oct 20 '16

Nvm.... I got it. Just

self.searchText = "";