Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error TS2554: Expected 1 arguments, but got 0. Angular6

i have this problem, my app working fine but this error shows in IDE.

employee.service.ts :

import { Injectable } from '@angular/core';
@Injectable({
  providedIn: 'root'
})
export class EmployeeService {
getEmployee(){
  return [
    {"id":1,"name":"Micheal","age":21},
    {"id":2,"name":"Jackson","age":22},
    {"id":3,"name":"Hales","age":23},
    {"id":4,"name":"Moz","age":25}
  ];
}
  constructor() { }
}

and my employeeDetail.ts file is this:

import { Component, OnInit } from '@angular/core';
import { EmployeeService } from '../services/employee.service';

@Component({
  selector: 'employee-detail',
  templateUrl: './employee-detail.component.html',
  styleUrls: ['./employee-detail.component.css']
})
export class EmployeeDetailComponent implements OnInit {

  public employees = [];
  constructor(private _employeeService : EmployeeService) {

   }

  ngOnInit() {
    this.employees = this._employeeService.getEmployee();
  }

}

Here is the Employee-list.ts

import { Component, OnInit } from '@angular/core';
import {HttpClientModule} from '@angular/common/http';
import { EmployeeService } from '../services/employee.service';

@Component({
  selector: 'employee-list',
  templateUrl: './employee-list.component.html',
  styleUrls: ['./employee-list.component.css']
})
export class EmployeeListComponent implements OnInit {

  public employees = []



  constructor(private _employeeService : EmployeeService) { 


  }

  ngOnInit() {
    this.employees = this._employeeService.getEmployee();
  }

}

how can I solve this problem? what is the actual problem? as I am new to angular6 so I cannot figure out the error, please explain this. Thank you.

like image 609
Fahim Khan Avatar asked Sep 05 '18 19:09

Fahim Khan


1 Answers

I do not see any issue with your code, as i see you should stop the applicaiton with Ctrl + C

and then do ng serve

Anyhow the reason being is that, your getEmployee method still needs one parameter to be passed, just make sure your code is saved on the service part.

like image 160
Sajeetharan Avatar answered Sep 30 '22 04:09

Sajeetharan