[英]Getting Uncaught Error: Type MyModule does not have 'ɵmod' property
[英]ERROR Error: Uncaught (in promise): Error: ASSERTION ERROR: Type passed in is not ComponentType, it does not have 'ɵcmp' property
我的 Angular 应用程序中有一个指向外部 url 的链接。我正在使用 Angular 路由器,当我单击该链接时在控制台中收到此错误:
ERROR Error: Uncaught (in promise): Error: ASSERTION ERROR: Type passed in is not ComponentType, it does not have 'ɵcmp' property. Error: ASSERTION ERROR: Type passed in is not ComponentType, it does not have 'ɵcmp' property.
我意识到我的“安装应用程序组件”中没有@Component 装饰器,只是想知道如何解决这个问题,因为我的“安装应用程序组件”不需要 ts 或 scss 文件。
来自我的 app-routing.module.ts:
const routes: Routes = [
{path: 'login', component: LoginPageComponent, canActivate: [LoginCanActivate]},
{path: 'login/:logout', component: LoginPageComponent},
{path: 'new-password', component: LoginNewPasswordComponent},
{path: 'forgot-password', component: ForgotPasswordComponent},
{
path: 'install-app',
canActivate: [InstallAppComponent],
component: InstallAppComponent,
},
从我的配置服务中获取外部 url 的“组件”:
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, Router, RouterStateSnapshot } from '@angular/router';
import { AppConfigService } from '../services/app-config.service';
@Injectable({
providedIn: 'root'
})
export class InstallAppComponent implements CanActivate {
constructor(private router: Router, private appConfigService: AppConfigService) { }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
window.location.href = this.appConfigService.getConfig().fieldInstallUrl;
return true;
}
}
我在哪里创建链接 ts:
{
label: 'INSTALLATION APP',
icon: 'build_circle',
link: './install-app',
index: 4
},
html
<a
*ngIf="link.link"
mat-tab-link
[routerLink]="link.link"
routerLinkActive
#rla="routerLinkActive"
[active]="rla.isActive"
(click)="refreshView(link.link)"
>
{{ link.label }}
</a>
<a *ngIf="link.handler" mat-tab-link (click)="link.handler()">
{{ link.label }}
</a>
我认为你必须选择。
install-app
,以便您可以完全删除该路由InstallAppComponent
成为一个组件。 为什么它是CanActivate
? 您可以改为在组件的 ngOnInit 中进行路由。 scss 文件是可选的,不是强制性的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.