I am encountering some issues with my code and this is the error message I am receiving:
'The argument of type 'Employee' is not assignable to the parameter of type' any [] '. The 'includes' property is missing in the 'Employee' type.
This is the service I am using:
import { Injectable } from '@angular/core';
import { AngularFireDatabase, AngularFireList, AngularFireObject } from 'angularfire2/database';
import { Observable } from 'rxjs';
import { Employee } from '../Employee';
import { FirebaseApp } from 'angularfire2';
@Injectable()
export class EmployeeService {
employees: AngularFireList<any[]>;
Employee: AngularFireObject<any>;
constructor(
public af: AngularFireDatabase
) {
this.employees = this.af.list('/employees/employees') as AngularFireList <Employee[]>;
}
getEmployees(): AngularFireList <any> {
return this.employees ;
}
addEmployee(emp:Employee)
{
return this.employees.push(emp);
}
}
and this is my component:
import { Component, OnInit } from '@angular/core';
import { Employee } from '../../Employee';
import { FlashMessagesService } from 'angular2-flash-messages';
import { timeout } from 'q';
import { Router } from '@angular/router';
import { EmployeeService } from '../../services/employee.service';
@Component({
selector: 'app-add-employee',
templateUrl: './add-employee.component.html',
styleUrls: ['./add-employee.component.css']
})
export class AddEmployeeComponent implements OnInit {
employee:Employee={
firstName:"",
lastName:"",
email:"",
country:"",
city:"",
phone:0,
salary:0
}
disableSalary:boolean=true;
constructor(public fashMessagesService : FlashMessagesService, public router:Router,
public employeeService : EmployeeService
) { }
ngOnInit() {
}
mySubmit({value,valid}:{value:Employee,valid:boolean}){
if(this.disableSalary){
value.salary=0;
}
if (!valid) {
this.fashMessagesService.show('Please Write Correct Info',{cssClass:'alert-danger',timeout:3000});
//console.log("not correct data");
this.router.navigate(['add-employee']);
}else {
this.employeeService.addEmployee(value);
this.fashMessagesService.show('Added Successfully!',{cssClass:'alert-success',timeout:3000});
this.router.navigate(['/']);
//console.log(this.employee);
}
}
}
I am unsure about the exact problem, but I hope someone can figure it out.