1

I have function in component.ts like below

    visability=true;
    showTextBox(){
      debugger;
      this.visability = false;

    }

and in component.html below code I have

       <div class="col-sm">
          <div class="toggle">
            <input type="checkbox"  class="check">
            <!-- (click)="show=!show" -->
            <b class="b switch" ></b>
            <b class="b track"></b>
          </div>
          <h4 id="door-delivery">Door Delivery</h4>
        </div>
        <div class="col-sm address">
          <div *ngIf="!visability" (click)="showTextBox()">
            <input class="form-control " type="text" placeholder="Enter Address">
          </div>
          <div *ngIf="visability" (click)="showTextBox()">
            <select formControlName="pickup_location" class="form-control selectpicker" id="select-city" data-live-search="true" required>
              <option data-tokens="" disabled>
                <h2>Pickup location...</h2>
              </option>
              <option data-tokens="India">
                <h2>India</h2>
              </option>
              <option data-tokens="UAE">
                <h2>UAE</h2>
              </option>
              <option data-tokens="Japan">
                <h2>Japan</h2>
              </option>
            </select>
          </div>
        </div>

My Toggle Looks like My Question is when I click on toggle it should appear Enter pickup location and as well as again if I click on toggle it should be display the list of cities.

How we can achieve this? could any one help me

1
  • 1
    In your function instead of setting visibitlity to false you can just set it to the opposite of what it currently is with ! operator. visibility = !visibility Commented Aug 22, 2018 at 10:23

2 Answers 2

1

add click on your div holding toggle button as:

<div class="toggle" (click)=toggleTextBox()>
    <input type="checkbox"  class="check">
    <b class="b switch" ></b>
    <b class="b track"></b>
</div>

TS

visability=true;
toggleTextBox(){
  this.visability = !this.visability;
}

no need of (click)="showTextBox()" in div under <div class="col-sm address">.

Sign up to request clarification or add additional context in comments.

Comments

0

You can use directly in your template :

(click)="visability = !visability"

1 Comment

It is important to respect the space before and after the =. Can you try to move it on the parent <div>?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.