Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Shawn Rieger
Shawn Rieger
9,916 Points

Angular - Comment form - Not getting value from textarea.

Augury shows form component with only one input and no textarea field.

entry-comment-form.component.html

<form (submit)="onSubmit()">
    <div>
        <label for="name">Name</label>
        <input type="text" name="name" [(ngModel)]="name">
    </div>
    <div>
        <label for="comment">Comment</label>
        <textarea name="comment"></textarea>
    </div>
    <div>
        <button>Submit</button>
    </div>
</form>

entry-comment-form.component.ts

import { Component, EventEmitter } from "@angular/core";

@Component({
    selector: 'app-entry-comment-form',
    templateUrl: 'entry-comment-form.component.html'
})

export class EntryCommentFormComponent {
    name: string = "";
    comment: string = "";
    onCommentAdded = new EventEmitter<{name: string, comment: string;}>();
    onSubmit() {
        let comment = { name: this.name, comment: this.comment };
        debugger;
        this.onCommentAdded.emit(comment);
    }
}

Screenshot 1

Augury

Screenshot 2

Augury

2 Answers

Seth Kroger
Seth Kroger
56,413 Points

Looks like you forgot the ngModel on the textarea for the comment.

Shawn Rieger
Shawn Rieger
9,916 Points

Ok, that works now, thanks! However the event emitter isn't working, the onCommentAdded is never invoked.