Angular 应用程序无法找到我的界面文件

发布于 2025-01-17 00:38:06 字数 2469 浏览 3 评论 0原文

我正在尝试为 OMBD Api 制作一个简单的测试床。我有以下名为 ombdresponse.ts 的接口文件:

interface IOMBDResponse {
    Title: string;
    Year: string;
    Director: string;
    Poster: string;
}

我遇到的错误位于我的 ombd-api.service.ts 中:

import { Injectable } from '@angular/core';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import { catchError, tap } from 'rxjs';
import { throwError } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class OmbdApiService {

  private _siteURL="https://www.ombdapi.com/";
  private _key = '?apikey=63455f5a';


  constructor(private _http:HttpClient) { }

  getMovieData(movieName): Observable<IOMBDResponse> {
    return this._http.get<IOMBDResponse>(this._siteURL + this._key + movieName)
    .pipe(
      tap(data => console.log('Moviedata/error' + JSON.stringify(data))
      ),
      catchError(this.handleError)
    );
  }

  private handleError(err:HttpErrorResponse) {
    console.log('OmbdApiService: ' + err.message);
    return throwError(err.message);
  }


}

的 app.component.ts 中也有相同的错误:

import { Component } from '@angular/core';
import { Axios } from 'axios';
import { OmbdApiService } from './services/ombd-api.service';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
 
})
export class AppComponent {
  title = 'openstackProject';

  movieData:IOMBDResponse;
  
 
  errorMessage: any;

  constructor(private _ombdService: OmbdApiService) {

  }

  getMovieDetails(movieName:string) : boolean {
    this._ombdService.getMovieData(movieName).subscribe(
      movieData => {
        this.movieData=movieData;
        console.log('Director name: ' + this.movieData.Director);
      },
      error => this.errorMessage = <any>error
    );
    return false;
  }

}

我收到以下两个错误:

Error: src/app/services/ombd-api.service.ts:19:27 - error TS2304: Cannot find name 'IOMBDResponse'.

19     return this._http.get<IOMBDResponse>(this._siteURL + this._key + movieName)
                             ~~~~~~~~~~~~~

所以

Error: src/app/app.component.ts:14:13 - error TS2304: Cannot find name 'IOMBDResponse'.

14   movieData:IOMBDResponse;

我 显然该应用程序在查找我的界面文件时遇到问题。但是,接口文件会出现在智能感知中。 有人可以解释我做错了什么吗?

尝试将接口公开。我对使用 Angular 的外部 API 非常陌生。

Im trying to make a simple test bed for the OMBD Api. I have the following interface file called ombdresponse.ts:

interface IOMBDResponse {
    Title: string;
    Year: string;
    Director: string;
    Poster: string;
}

The error I am having lies in my ombd-api.service.ts:

import { Injectable } from '@angular/core';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import { catchError, tap } from 'rxjs';
import { throwError } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class OmbdApiService {

  private _siteURL="https://www.ombdapi.com/";
  private _key = '?apikey=63455f5a';


  constructor(private _http:HttpClient) { }

  getMovieData(movieName): Observable<IOMBDResponse> {
    return this._http.get<IOMBDResponse>(this._siteURL + this._key + movieName)
    .pipe(
      tap(data => console.log('Moviedata/error' + JSON.stringify(data))
      ),
      catchError(this.handleError)
    );
  }

  private handleError(err:HttpErrorResponse) {
    console.log('OmbdApiService: ' + err.message);
    return throwError(err.message);
  }


}

I also have the same error in my app.component.ts:

import { Component } from '@angular/core';
import { Axios } from 'axios';
import { OmbdApiService } from './services/ombd-api.service';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
 
})
export class AppComponent {
  title = 'openstackProject';

  movieData:IOMBDResponse;
  
 
  errorMessage: any;

  constructor(private _ombdService: OmbdApiService) {

  }

  getMovieDetails(movieName:string) : boolean {
    this._ombdService.getMovieData(movieName).subscribe(
      movieData => {
        this.movieData=movieData;
        console.log('Director name: ' + this.movieData.Director);
      },
      error => this.errorMessage = <any>error
    );
    return false;
  }

}

I get the following two errors:

Error: src/app/services/ombd-api.service.ts:19:27 - error TS2304: Cannot find name 'IOMBDResponse'.

19     return this._http.get<IOMBDResponse>(this._siteURL + this._key + movieName)
                             ~~~~~~~~~~~~~

and

Error: src/app/app.component.ts:14:13 - error TS2304: Cannot find name 'IOMBDResponse'.

14   movieData:IOMBDResponse;

So clearly the app is having an issue finding my Interface file. However, the interface file comes up in intellisense.
Can someone explain what I am doing wrong?

Tried making the interface public. I am very new to using external APIs with angular.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

星光不落少年眉 2025-01-24 00:38:06

您需要像这样

export interface IOMBDResponse {
    Title: string;
    Year: string;
    Director: string;
    Poster: string;
}

在需要的地方导出和导入您的界面 import { IOMBDResponse } from '/directory/'

You need to export and to import your interface like this

export interface IOMBDResponse {
    Title: string;
    Year: string;
    Director: string;
    Poster: string;
}

and where you need it import { IOMBDResponse } from '/directory/'

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文