繁体   English   中英

角度-错误TS2554:应使用0个参数,但得到3个

[英]Angular - error TS2554: Expected 0 arguments, but got 3

我遇到以下错误:

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.

我是Angular的新手,我的代码似乎与我正在关注的教程相同。

我的代码可以在下面看到

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();
      }));
    });

更新

根据以下评论中的要求。

Coffee.ts:

    class Coffee {

        // Properties
        type: string;
        rating: number;
        notes: string;
        tastingRating: TastingRating;

        constructor(public name: string, public place: string, public location: PlaceLocation) {

        }
    }

如果需要PlaceLocation.ts

    class PlaceLocation {

        constructor(public address: string = "", 
                    public city: string = "",
                    public latitude: number = null,
                    public longitude: number = null) {

                    }
    }

从现有类创建新对象之前,我想您想将其导入组件中。

import {Coffee} from '<relative path>'

尝试从正确的路径导入咖啡。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM