Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
message: '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
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);
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);
The AngularFireList
type expects a single type for what the list will contain, not an array type. The correct declaration for the employees
array would be employees: AngularFireList<Employee>
(not Employee[]
, not any[]
).
The reason it's failing now is because it's expecting you to pass in something of type any[]
to .push()
, and Employee
is not assignable to any[]
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.