1

Can you please tell me to Toggle Show and Hide div content using button click event without using variable and event binding. Sample code

<form>
   <div *ngIf="--CAPTURE BUTTON CLICK EVENT HERE--">
     <span>Welcome</span>
   </div>
   <button type="submit">Click Me</button>
</form>

Please suggest me the solution How to listen button click event in *ngIf.

4
  • what do you need that for? Commented Aug 2, 2019 at 19:45
  • not clear what you're asking at all... click binding syntax is basic angular, read the docs if not familiar. If there's some reason you think standard event binding won't work, make it clear why and what you're trying to accomplish Commented Aug 2, 2019 at 19:45
  • I'm not really sure what you want to achieve here, you only want the button to be displayed while the user is clicking in the button ? If not why don't you use a variable that changes value when the user clicks the button? Commented Aug 2, 2019 at 19:51
  • TO achieve this question stackoverflow.com/questions/57315314/… Commented Aug 3, 2019 at 3:34

1 Answer 1

0

You can do by this

<form>
   <div *ngIf="state">
     <span>Welcome</span>
   </div>
   <button type="submit" (click)=state = !state>Click Me</button>
</form>
Sign up to request clarification or add additional context in comments.

3 Comments

First I think you forgot to add "..." after the action definition of the click event. Second, the user clearly asked that no variable can be used.
@piotrszybicki i understand what user said but the answer was assuming for achieving the outcome, as its not clearly mention why he was doing it.

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.