也许它已经在主题中的某个地方了。但我找不到类似的问题。问题是为什么 Angular 找不到模块和服务。我通过“ng g”创作,似乎一切都应该收紧。但它会给你一个错误或警告。
服务本身有几个方法(函数):
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class NameServices{...}
如何将其导入到组件中:
import {NameServices} from '../../@core/utils/NameServices.service';
控制台出现的问题:
▲ [WARNING] Import "NameServices" will always be undefined because the file "src/app/@core/utils/NameServices.service.ts" has no exports [import-is-undefined]
src/app/pages/home/home.component.ts:5:9:
5 │ import {NameServices} from '../../@core/utils/NameServi...
╵ ~~~~~~~~~~~~~~~~~~~~~~~
X [ERROR] TS1490: File appears to be binary. [plugin angular-compiler]
src/app/@core/utils/NameServices.service.ts:0:0:
0 │
╵ ^
X [ERROR] TS2306: File '*:/Projects/client/src/app/@core/utils/NameServices.service.ts' is not a module. [plugin angular-compiler]
src/app/pages/home/home.component.ts:7:38:
7 │ ...rvices} from '../../@core/utils/NameServices.service';
我已经尝试过改变很多事情。在 tsconfig 中,我手动指定了路径,更改了“模块”版本等等,这通常会导致很多问题。
也许有必要加强App.module.ts中的依赖关系?
(它似乎有效。但我厌倦了控制台中的这些污垢。)
import {
NameServices
} from '../../@core/utils/NameServices.service';
@Component({
selector: 'your-component',
standalone: true,
imports: [
NameServices
],
templateUrl: './your.component.html',
styleUrl: './your.component.scss',
})
export class YourComponent {
constructor(private nameServices: NameServices) {}
}