Шаблонные формы. undefined Шаблонные формы.

Шаблонные формы.

Open in new window

<<<<<<< HEAD

Шаблонные формы.

class GoodComment {
    constructor(
      public author: string,
      public content: string,
    ) {  }

  }

import { Component } from '@angular/core';


@Component({
  selector: 'app-comment-form',
  template: `
     <h1>Comment form</h1>

     <form #heroForm="ngForm">
     <div class="form-group">
       <label for="name">Author</label>
       <input [(ngModel)]="model.author" name="author" type="text" class="form-control" id="name" required>
     </div>

     <div class="form-group">
       <label for="alterEgo">Content</label>
       <textarea name="content" [(ngModel)]="model.content" class="form-control"></textarea>
     </div>

     <button type="submit" class="btn btn-success">Submit</button>

     </form>
     {{ model | json}}
  `,
  styles: ['']
})
export class CommentFormComponent {


  model = new GoodComment('Dima', 'Very nice!');

  submitted = false;

  onSubmit() { this.submitted = true; }


}

Angular did. Angular automatically creates and attaches an NgForm directive to the

tag.

The NgModel directive doesn’t just track state; it updates the control with special Angular CSS classes that reflect the state.

======= Шаблонные формы.

9a1996c815c4e99cadc0b09a4512711c0c419919

Other topics