Angular 应用程序无法找到我的界面文件
我正在尝试为 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要像这样
在需要的地方导出和导入您的界面
import { IOMBDResponse } from '/directory/'
You need to export and to import your interface like this
and where you need it
import { IOMBDResponse } from '/directory/'