1

I'm new to Angular and want to start with something simple to learn.

I'm currently developing a form and have divs which I need to toggle upon user selection. Do I need to create Angular 6 component to create such a toggle function?

How can I do the toggle - whether with component or without (if possible)?

Thanks

nickornotto
  • 1,946
  • 4
  • 36
  • 68

1 Answers1

5

You could try something like:

const isOpened = true;

<div *ngIf="isOpened">
<form> </form>
<div>

<div *ngIf="!isOpened">
<form> </form>
<div>
Idriss Neumann
  • 3,760
  • 2
  • 23
  • 32
Anthony Agbator
  • 488
  • 3
  • 6
  • Thanks @Anthony Is that angularJs or Angular 6? Can I just install Angular 6 into existing application and use the above code within a MVC view template? – nickornotto Jun 20 '18 at 14:00
  • While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – Derek Brown Jun 20 '18 at 15:09
  • I have installed new angular project and moved its files into my existing project. Then applied your code and it doesn't work. I also used the example from this solution: https://stackoverflow.com/questions/32830190/angularjs-toggle-div-visibility and it doesn't work either. I am not sure it is because the angular in my project not working or I am missing something in my template to make angular working. – nickornotto Jun 21 '18 at 14:42
  • 1
    it works for all version of angular from 2 through 6. – Anthony Agbator Jun 27 '18 at 08:09