To learn Angular I'm coding a to-do list. I've created a component task with a title (task name) and status (a boolean related to a checkbox input) parameters.
<div>
<div>{{title}} <button>Edit</button></div>
<input type="checkbox" value={{status}}>
</div>
I've also created a ToDoList component which contain a title(name of the to-do list, and a tab with a list of task name to generate multiple task component using a *ngFor.
<div>
<h1>{{title}}</h1>
<app-task *ngFor="let title of list" [title]="title" status="true"></app-task>
<button (click)="appTaskDirective">Add a task</button>
</div>
Now I want to add dynamically task components on click on the "Add a task button" while using the appTaskDirective but I just can't figure it out.
The angular document example can't help.
Here is my appTaskDirective file:
import { Directive, ViewContainerRef, TemplateRef, OnInit } from '@angular/core';
@Directive({
selector: '[appTaskDirective]'
})
export class TaskDirectiveDirective implements OnInit {
constructor(public viewContainer:ViewContainerRef) { }
}
Thanks.