Angular路由错误消息 - router-outlet is not a known element
发布日期:2021-06-30 14:44:21 浏览次数:2 分类:技术文章

本文共 1979 字,大约阅读时间需要 6 分钟。

我在application Component的HTML里定义了一个router-outlet元素:

遇到错误消息:

router-outlet is not a known element

查看其定义,源代码比文档更有说服力:

/** * @description * * Acts as a placeholder that Angular dynamically fills based on the current router state. * * Each outlet can have a unique name, determined by the optional `name` attribute. * The name cannot be set or changed dynamically. If not set, default value is "primary". * * ``` * 
*
*
* ``` * * A router outlet emits an activate event when a new component is instantiated, * and a deactivate event when a component is destroyed. * * ``` *
* ``` * @ngModule RouterModule * * @publicApi */export declare class RouterOutlet implements OnDestroy, OnInit {
private parentContexts; private location; private resolver; private changeDetector; private activated; private _activatedRoute; private name; activateEvents: EventEmitter
; deactivateEvents: EventEmitter
; constructor(parentContexts: ChildrenOutletContexts, location: ViewContainerRef, resolver: ComponentFactoryResolver, name: string, changeDetector: ChangeDetectorRef); ngOnDestroy(): void; ngOnInit(): void; get isActivated(): boolean; get component(): Object; get activatedRoute(): ActivatedRoute; get activatedRouteData(): Data; /** * Called when the `RouteReuseStrategy` instructs to detach the subtree */ detach(): ComponentRef
; /** * Called when the `RouteReuseStrategy` instructs to re-attach a previously detached subtree */ attach(ref: ComponentRef
, activatedRoute: ActivatedRoute): void; deactivate(): void; activateWith(activatedRoute: ActivatedRoute, resolver: ComponentFactoryResolver | null): void; static ɵfac: ɵngcc0.ɵɵFactoryDef
; static ɵdir: ɵngcc0.ɵɵDirectiveDefWithMeta
;}

是一个place holder,Angular根据当前的router state在运行时填充。

解决办法:

在AppModule里导入RouteModule即可:

更多Jerry的原创文章,尽在:“汪子熙”:

转载地址:https://jerry.blog.csdn.net/article/details/114108213 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:StackBlitz里无法重命名项目的问题
下一篇:SAP Spartacus里px,em和rem的应用

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2024年04月20日 00时21分53秒