Estou criando um componente que contem um select com todos os livros que vem da API. Vou usar esse select em outro componente para fazer o cadastro do emprestimo do livro, como faco para pegar o valor do select ? Estou tentando da seguinte maneira: book.select.component.html
<div class="form-group">
<label class="control-label">Book Name</label>
<select [(ngModel)]="model" name="livro" class="form-control">
<option *ngFor="let book of books" [ngValue]="book">{{book.nome}}</option>
</select>
</div>
book.select.component.ts
import { Component, Input } from "@angular/core";
import { BookComponent } from "./book.component";
import { BookService } from "./book.service";
@Component({
moduleId: module.id,
selector: 'select-book',
templateUrl: './book.select.component.html'
})
export class BookSelectComponent{
@Input() model;
books: BookComponent[] = [];
service: BookService;
constructor(service: BookService){
this.service = service;
service.getList()
.subscribe(books => {
this.books = books;
}, error => console.log(error));
}
}
loan.register.component.html
<div class="container">
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6">
<h1>New Loan</h1>
<form [formGroup]="form" (submit)="identifyAction($event)">
<select-book model="loan.livro"></select-book>
<select-user></select-user>
<div class="form-group">
<label class="control-label">Loan Date</label>
<input type="date" formControlName="dataEmprestimo" [(ngModel)]="loan.dataEmprestimo" name="dataEmprestimo"
class="form-control">
</div>
<div class="form-group">
<label class="control-label">Return Date</label>
<input type="date" formControlName="dataDevolucao" [(ngModel)]="loan.dataDevolucao" name="dataDevolucao"
class="form-control">
</div>
<div class="form-group">
<label class="control-label">Returned</label>
<input type="checkbox" formControlName="devolvido" [(ngModel)]="loan.devolvido" name="devolvido"
class="form-control">
</div>
<a [routerLink]="['']" class="btn btn-default">Back To List</a>
<button type="submit" class="btn btn-success">Register / Edit Loan</button>
</form>
</div>
<!--col-md-6-->
<div class="col-md-3"></div>
</div>
<!--row-->
</div>
<!--container-->