Я совершенно новичок в Angular2 и мне понадобится ваша помощь для выполнения нижеприведенного упражнения.Мне нужно добавить запись из текстового поля в span на HTML.Меня попросили внести изменения только в файл .ts
Я не могу понять, что необходимо добавить в AddMore, чтобы обеспечить добавление записи из текстового поля при нажатии кнопки рядом с флажком. Пожалуйста, помогите .
Angular.component.html:
<h1>Fresco PLAY Activity Tracker</h1>
<div>
<div *ngFor="let todo of todos; let i=index" class="todoItem">
<input type="checkbox" [(ngModel)]="todo.done" />
<span [ngClass]="{'checked': todo.done}">{{i+1}}. {{ todo.desc }}</span>
</div>
<span *ngIf="todos.length == 0">No Activities to track! Start by adding one</span><br/>
<input id="newTodo" type="text" [(ngModel)]="newToDo">
<span *ngIf="error" style="color:red;">Please enter an activity!</span>
<br/>
<button id="addActivity" (click)="addMore()">Add an Activity!</button>
<button id="clearAll" (click)="clearAll()">Clear All</button>
</div>
App.component.ts:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
//Define your variables done,todos,newToDo,newToDoObj,error
public done: boolean;
public todos : any;
public newToDo : string;
public newToDoObj : any;
public error : boolean;
//Define your constructor here with todos as [] ,newToDo as '' and error as false
constructor(){
this.todos = [];
this.newToDo = '';
this.error = false;
}
//Define your addMore function here
//Define your clearAll function here
addMore(){
}
clearAll(){
}
}