Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Write the code snippet for the specific scenario asked

Scenario #1: Html code snippet for the input text boxes for below.

Answer:

<input type="text" [(ngModel)]="firstName" (input)="updateFullName()" />


<input type="text" [(ngModel)]="lastName" (input)="updateFullName()" />

Scenario #2: Html code snippet for the iteration of string array ‘items’ as in below

Answer:

<ul>
<li *ngFor="let item of items; let i = index">
{{ item }}
<button (click)="removeItem(i)">Remove</button>
</li>
</ul>
Scenario #3: TS code snippet for the ‘Add’ new task button

Answer:

addTask() {
if (this.newTaskTitle.trim() !== '') {
const newTask: Task = {
id: this.tasks.length + 1,
title: this.newTaskTitle
};

this.tasks.push(newTask);
this.newTaskTitle = '';
}
}

You might also like