The template file

Each time we add a new answer, we need to give it a score value. The best thing we can do to properly handle this is to add a <select> element to the AnswerEditComponent template file so that the active user can pick a number from a list of allowed values.

Here's the full answer-edit.component.html template file, with the relevant code highlighted:

<h2>{{title}}</h2>
<div class="answer-edit">
<div>
<label for="text">Answer text:</label>
<br />
<textarea id="text" [(ngModel)]="answer.Text"
placeholder="enter a suitable text..."></textarea>
</div>

<div>
<label for="value">Score Value:</label>
<br />
<select id="value" name="value" [(ngModel)]="answer.Value">
<option *ngFor="let num of [-5,-4,-3,-2,-1,0,1,2,3,4,5]"
[value]="num">{{num}}</option>

</select>
</div>

<div>
<input *ngIf="editMode" type="button" value="Apply Changes"
(click)="onSubmit(answer)" />
<input *ngIf="!editMode" type="button" value="Create the
Answer!" (click)="onSubmit(answer)" />
<input type="button" value="Cancel" (click)="onBack()" />
</div>
</div>

By doing so, our users will be able to give each answer a value from a minimum of -5 to a maximum of 5. Needless to say, this is just an example; we're free to let the user pick the number they want by setting wider boundaries or by replacing the <select> element with an <input type="number" /> element; as always, the choice is ours.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.120.136