"文件不是模块"错误

时间:2017-09-05 15:47:25

标签: angular

我按照教程进行操作,并在重新编译应用程序时看到错误。我已尝试将其与其他应用进行比较,但我无法将其与之相提并论。

  

/../ app / public-deals.component.ts(2,22):文件' /../ app / deal.ts'是   不是一个模块。 /../app/deal.service.ts(6,22):文件' /../ app / deal.ts'   不是一个模块。

根据控制台,错误发生在两个文件中:

公开-deals.component.ts

import { Component, OnInit } from '@angular/core';
import { Deal } from './deal';
// We haven't defined these services yet
// import { AuthService } from './auth.service';
import { DealService } from './deal.service';

@Component({
  selector: 'public-deals',
  // We'll use an external file for both the CSS styles and HTML view
  templateUrl: 'public-deals.component.html',
  styleUrls: ['public-deals.component.css']
})
export class PublicDealsComponent implements OnInit {
  publicDeals: Deal[];

  // Note: We haven't implemented the Deal or Auth Services yet.
  constructor(
    private dealService: DealService,
    // private authService: AuthService
    ) {
  }
  // When this component is loaded, we'll call the dealService and get our public deals.
  ngOnInit(): void {
    this.dealService.getPublicDeals()
      .then(deals => this.publicDeals = deals);
  }

  purchase(item){
    alert("You bought the: " + item.name);
  }
}

deal.service.ts

import { Injectable } from '@angular/core';
import { Headers, Http, Response } from '@angular/http';

import 'rxjs/add/operator/toPromise';

import { Deal } from './deal';

@Injectable()
export class DealService {
  // Define the routes we are going to interact with
  private publicDealsUrl = 'http://localhost:3001/api/deals/public';
  private privateDealsUrl = 'http://localhost:3001/api/deals/private';

  constructor(private http: Http) { }

  // Implement a method to get the public deals
  getPublicDeals() {
    return this.http
      .get(this.publicDealsUrl)
      .toPromise()
      .then(response=>response.json() as Deal[])
      .catch(this.handleError);
  }

  // Implement a method to get the private deals
  getPrivateDeals() {
    return this.http
      .get(this.privateDealsUrl)
      .toPromise()
      .then(response=>response.json() as Deal[])
      .catch(this.handleError);
  }

  // Implement a method to handle errors if any
  private handleError(error: any): Promise<any> {
    console.error('An error occurred', error);
    return Promise.reject(error.message || error);
  }
}

接口

export interface Deal {
  id: number;
  name: string;
  description: string;
  originalPrice: number;
  salePrice: number;
}

我已经查看了其他导入界面的应用,但我无法看到我出错的地方。

0 个答案:

没有答案