2

So, I have an inout field, and I want to clear the text field when I click on Send, I'm not sure how to do that in typescript for ionic.

This is my code:

 <ion-footer>
    <ion-item>
        <ion-input id="testId" type="text" placeholder="Type your Message here..." [(ngModel)]="newmessage"></ion-input>
        <button ion-button clear item-right (click)="send()">Send</button>
    </ion-item>
</ion-footer>

This is my Ts file

 send(){

    this.ref.push({
        //key:this.ref.push().key("hello"),
        name: this.name,
        message: this.newmessage,
        phNo: this.data3,


    });

2 Answers 2

2

Hi, does this helps?

send(){
    this.ref.push({
        //key:this.ref.push().key("hello"),
        name: this.name,
        message: this.newmessage,
        phNo: this.data3,
    });
    this.newmessage = ""; //clear this.newmessage
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Exactly, how do you do this for number field? I can set the linked variable to zero but what if I don't want the zero to be displayed? What if I just want to clear the input field to the initial (empty) state? I mean when running in browser you can also assign the number to '' but that won't work when you try to compile the typescript for Android...
0

check this

 <ion-view title="Standard">
  <ion-content class="has-header" ng-controller="calcCtrl">
    <form id="calcForm" name="calcForm" ng-submit="submitData(calculate)">
      <label class="item-input">
        <span class="input-label">Price</span>
        <input class="input-label" type="text" placeholder="$0.00" ng-model="calculate.price">
      </label>

      <label class="item-input ">
        <span class="input-label">Discount</span>
        <input class="input-label" type="text" placeholder="$0.00" ng-model="calculate.discount">
      </label>
    </form>
  </ion-content>

  <ion-footer-bar class="bar-stable">
    <div class="buttons pull-right">
      <button class="button button-positive" ng-click="resetForm()">Clear</a>
    </div>
  </ion-footer-bar>
</ion-view>






  $scope.clearFields = function() {
$scope.calculate = angular.copy(calcForm);
$scope.calcForm.$setPristine();
}

Check this

1 Comment

working on angular 4 with typescript,so this doesn't help,thanks anyway :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.