Reputation: 647
I am running into the following ERROR:
src/app/data.service.ts(11,7): error TS2554: Expected 0 arguments, but got 3.
src/app/data.service.ts(12,7): error TS2554: Expected 0 arguments, but got 3.
I am new to Angular and my code appears to be the same as the tutorial I am following.
My code can be seen below
data.service.ts:
import { Injectable } from '@angular/core';
@Injectable()
export class DataService {
constructor() { }
getList(callback) {
//TODO: Change it with a real Web Service
const list = [
new Coffee("Double Espresso", "Sunny Cafe", new PlaceLocation("123 Market St", "San Francisco")),
new Coffee("Caramel Americano", "Starcoffee", new PlaceLocation("Gran Via 34", "Madrid"))
];
callback(list);
}
save(coffee, callback) {
//TODO: Change it with a real Web Service
callback(true);
}
}
data.service.spec.ts:
import { TestBed, inject } from '@angular/core/testing';
import { DataService } from './data.service';
describe('DataService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [DataService]
});
});
it('should be created', inject([DataService], (service: DataService) => {
expect(service).toBeTruthy();
}));
});
As requested in comments below.
Coffee.ts:
class Coffee {
// Properties
type: string;
rating: number;
notes: string;
tastingRating: TastingRating;
constructor(public name: string, public place: string, public location: PlaceLocation) {
}
}
In case PlaceLocation.ts is needed:
class PlaceLocation {
constructor(public address: string = "",
public city: string = "",
public latitude: number = null,
public longitude: number = null) {
}
}
Upvotes: 1
Views: 8441
Reputation: 1082
before you create new object from existing class I think you want to import it in the component.
import {Coffee} from '<relative path>'
try importing Coffee from correct path.
Upvotes: 1