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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
留言是一种美德,欢迎回访!
[***.207.175.100]2024年04月20日 00时21分53秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Request_原理
2019-05-01
Request_继承体系
2019-05-01
Request_获取请求行数据_方法介绍
2019-05-01
spring的优势
2019-05-01
编写jdbc的工程代码用于分析程序的耦合
2019-05-01
工厂模式解耦的升级版
2019-05-01
hrm中的jwt认证:获取用户数据
2019-05-01
前端权限控制:获取用户信息接口构造数据
2019-05-01
前端权限控制:前端菜单控制
2019-05-01
前端权限控制:实现思路分析-待修改
2019-05-01
有状态服务和无状态服务
2019-05-01
基于jwt的用户鉴权:配置拦截器并测试
2019-05-01
POI的概述
2019-05-01
POI文件导入:跨服务器调用查询部门信息
2019-05-01
DataURL:概述
2019-05-01
DataURL:实现原理及优缺点分析
2019-05-01
DataURL:实现员工头像保存
2019-05-01
DataURL:员工头像回显
2019-05-01
七牛云存储:通过SDK上传图片
2019-05-01
七牛云存储:断点续传
2019-05-01