Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了未处理的Promise rejection:无法找到加载组件Angular2的主要插座大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用angular2-seed项目作为基础并引用angular2-login-seed来实现登录功能.但是我收到以下错误.
我查看了其他问题涉及相同的错误,但无法弄清楚我的代码有什么问题.请帮忙.

Unhandled Promise rejection: CAnnot find priMary outlet to load 'HomeComponent' ; Zone: angular ; Task: Promise.then ; Value: Error: CAnnot find priMary outlet to load 'HomeComponent'

我的应用组件代码

@Component({
  modulEID: module.id,SELEctor: 'sd-app',viewProviders: [NameListservice,http_PROVIDERS],templateUrl: 'app.component.html',directives: [ROUTER_DIRECTIVES,NavbarComponent,ToolbarComponent]
})
export class AppComponent {
  constructor() {
     console.log('Environment config',Config);
  }
}

app.component.HTML代码

<sd-navbar><router-outlet></router-outlet></sd-navbar>

应用路由配置:

const routes: RouterConfig = [
  {
    path: 'login',component: LoginComponent,canActivate: [UnauthenticatedGuard]
  },...HomeRoutes,];

export const APP_ROUTER_PROVIDERS = [
   provideRouter(routes),UnauthenticatedGuard,HomeComponentGuard
];

HomeRoutes代码

export const HomeRoutes = [
{
   path: '',component: HomeComponent,canActivate: [HomeComponentGuard],children: [
     { path: '',component: HomeComponent },{ path: 'home',{ path: 'about',component: AboutComponent }
   ]
 },];

Home.Component代码

import { Component } from '@angular/core';
import { ROUTER_DIRECTIVES } from '@angular/router';
import { NameListservice } from '../shared/index';

@Component({
  modulEID: module.id,SELEctor: 'wrapper',templateUrl: 'home.component.html',styleUrls: ['home.component.css'],directives: [ROUTER_DIRECTIVES]
})
export class HomeComponent {
   newName: String;
   constructor(public nameListservice: NameListservicE) {
      console.log("nameList: " + JSON.Stringify(nameListservice.get()));
   }

   addName(): Boolean {
     this.nameListservice.add(this.newName);
     this.newName = '';
     return false;
   }

}

解决方法

然这不是你预期的答案,但我们都有的问题( Cannot find primary outlet to load ‘LocalizationListComponent’)是这是一种故意的行为.

每位家长必须拥有< router-outlet>< / router-outlet>.以下是对github https://github.com/angular/angular/issues/10686回复.

我整整花了两天时间试图解决这个问题.我想删除子项或loadChildren并在同一级别处理所有内容是其中一种方法.

这是路由器的一个非常令人困惑和无法记录的功能.

大佬总结

以上是大佬教程为你收集整理的未处理的Promise rejection:无法找到加载组件Angular2的主要插座全部内容,希望文章能够帮你解决未处理的Promise rejection:无法找到加载组件Angular2的主要插座所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。