如何在提交表单后清除Angular Material Input文本

时间:2017-09-04 13:55:14

标签: angularjs angularjs-material

<div class="col-md-12 addUsercls">
   <div class="col-md-12 add-user-input">
      <md-content style="margin: 10px 10px 0px 10px;border-bottom: 1px solid #c9c9c9;">
         <md-autocomplete  
            ng-model="genericAlert.autocompletevalue"
            ng-disabled="isDisabled"
            md-no-cache="noCache"
            md-selected-item="selectedItem"
            md-search-text="searchText"
            md-items="item in querySearch(searchText)"
            md-item-text="item.name"
            md-min-length="0"
            placeholder="Type to find data, groups or expertise">
            <md-item-template>
               <span md-highlight-text="searchText" md-highlight-flags="^i">{{item.name}}</span>
            </md-item-template>
            <md-not-found>No states matching "{{searchText}}" were found.</md-not-found>
         </md-autocomplete>
      </md-content>
   </div>
   <div class="col-md-12">
      <i style="position: absolute;right:3px;top:-29px;cursor:pointer;" class="e2e-add-people" ng-click="showUserInfo(selectedItem);"></i>
      <ul class="adduseremail" id="adduseremail">
         <li ng-repeat="userName in userNames track by $index"> {{ userName }} </li>
      </ul>
   </div>
</div>

1 个答案:

答案 0 :(得分:0)

$scope.genericAlert.autocompletevalue = null;

在提交后在提交中执行此操作,并且应将其清除并仍保留其数据,例如

<button type="button" ng-click="Submit()">Submit</button>

HTML ^

        $scope.Submit = function() {
            $http.post('/test').then(function(result){
               $scope.genericAlert.autocompletevalue = null;
            })
         }

JS ^