我创建了第二个独立的AppNavComponent
组件on Stackblitz。
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterOutlet } from '@angular/router';
@Component({
standalone: true,
selector: 'app-nav',
imports: [CommonModule, RouterOutlet],
template: `<router-outlet>`,
})
export class AppNavComponent {
name = 'Angular';
}
它导入main
如下:
@Component({
selector: 'my-app',
standalone: true,
imports: [CommonModule, AppNavComponent],
template: `
<h1>Hello from {{name}}!</h1>
<a target="_blank" href="https://angular.io/start">
Learn more about Angular
</a>
`,
})
它会产生错误:
Cannot find module 'app-nav.component' or its corresponding type declarations.
有什么想法?
2条答案
按热度按时间f0ofjuux1#
更改此行:
到这一行:
7ivaypg92#
更改main.ts中
AppNavComponent
的导入,以指示该组件与当前文件位于同一目录。从
import { AppNavComponent } from 'app-nav.component';
to
import { AppNavComponent } from './app-nav.component';
Forked Working Example