请帮助我,我想绑定一个接口,即
export interface IEmployee {
code: string;
name: string;
gender: string;
}
用我的Html即
<div class="col-lg-6">
<div class="form-group">
<label class="control-label">Code</label>
<input type="text" class="form-control" [(ngModel)]="employees.code"/>
</div>
<div class="form-group">
<label class="control-label">Name</label>
<input type="text" class="form-control" [(ngModel)]="employees.name" />
</div>
<div class="form-group">
<label class="control-label">Gender</label>
<input type="text" class="form-control" [(ngModel)]="employees.gender" />
</div>
<div class="form-group">
<input type="button" class="btn btn-primary" name="Add" value="Add" (click)="onClick(employees)"/>
</div>
</div>
点击按钮我想从html获取输入值到我的班级
import { Component,Input } from '@angular/core';
import { HttpModule } from '@angular/http';
import { IEmployee } from '../employee/employee';
import { HomeService } from './home.service';
@Component({
selector:'my-home',
templateUrl: 'app/home/home.component.html'
})
export class NewComponent
{
employees: IEmployee;
constructor(private _homeService: HomeService) {
}
onClick(employee: IEmployee) {
this._homeService.Add(employee);
}
}
但我得到以下错误click here!!的错误
export class Employee implements IEmployee{
code :string;
name : string;
}
零件
export class NewComponent
{
employee: Employee;
constructor(private _homeService: HomeService) {
employee = new Employee();
}
//This interface will ensure basic information that IEmployee will be passed
// to service
onClick(employee: IEmployee) {
this._homeService.Add(employee);
}
}