Angular2: No component factory found for function HomeComponent

Luke Vo

I have already checked this article (and this one). I do not even actually use dynamically loading (actually, I do not know what it is).

This is the error message and the Network scripts loading:

enter image description here

core.umd.js:3257 EXCEPTION: Uncaught (in promise): Error: No component factory found for function HomeComponent() {

I have the following code for routing (admin.router.ts):

import { NgModule } from "@angular/core";
import { RouterModule } from "@angular/router";
import * as Components from "./Components/all.component";

const Routes: any = [
    {
        path: "",
        component: [Components.HomeComponent],
    },
];

@NgModule({
    imports: [RouterModule.forRoot(Routes)],
    exports: [RouterModule],
})
export class AdminRoutingModule { }

Here are the `all.component code, it is to gather everything:

import { NgModule } from "@angular/core";

import { ShellComponent } from "./shell.component";
import { SidebarComponent } from "./sidebar.component";
import { HomeComponent } from "./home.component";

export * from "./home.component";
export * from "./shell.component";
export * from "./sidebar.component";

export const AllComponents: any[] = [
    ShellComponent,
    SidebarComponent,
    HomeComponent,
];

The HomeComponent (home.component.ts) that is causing the problem (no code in yet, not that I am cutting its content here):

import { Component } from "@angular/core";

@Component({
    moduleId: module.id,
    selector: "home",
    templateUrl: "/Admin/Template/Home",
})
export class HomeComponent {

}

Also, I notice, whatever component I use there causes the problem. And here is my App Module (admin.module.ts), I tried entryComponents but the error still happens:

import {NgModule} from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { RouterModule } from "@angular/router";

import * as Components from "./Components/all.component";
import { AdminRoutingModule } from "./admin.router";

@NgModule({
    imports: [
        BrowserModule,
        AdminRoutingModule,
    ],
    declarations: [Components.HomeComponent, Components.ShellComponent, Components.SidebarComponent],
    entryComponents: [Components.HomeComponent],
    bootstrap: [Components.ShellComponent],
})
export class AdminModule {

}

I am hosting it on IIS Express (ASP.NET MVC) if it is relevant. Please help me check the problem, I have tried exactly as the tutorial in Routing.


Here are the other files that you may need:

main.ts:

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AdminModule } from './admin.module';

const platform = platformBrowserDynamic();
platform.bootstrapModule(AdminModule);

Calling inside the HTML page:

System.import('Apps/Admin/main')
    .catch(function (err) {
        console.log(err);
    });

system.config.js:

/**
 * System configuration for Angular samples
 * Adjust as necessary for your application needs.
 */
(function (global) {
    System.config({
        paths: {
            // paths serve as alias
            'npm:': '/node_modules/'
        },
        // map tells the System loader where to look for things
        map: {
            // our app is within the app folder
            Apps: '/App/Pages',
            // angular bundles
            '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
            '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
            '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
            '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
            '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
            '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
            '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
            '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
            // other libraries
            'rxjs': 'npm:rxjs',
            'angular-in-memory-web-api': 'npm:angular-in-memory-web-api',
        },
        // packages tells the System loader how to load when no filename and/or no extension
        packages: {
            Apps: {
                main: 'main.js',
                defaultExtension: 'js'
            },
            rxjs: {
                defaultExtension: 'js'
            },
            'angular-in-memory-web-api': {
                main: './index.js',
                defaultExtension: 'js'
            }
        }
    });
})(this);
yurzui

Open your admin.router.ts file and find this line:

const Routes: any = [
  {
     path: "",
     component: [Components.HomeComponent], // this line
  },
];

Then replace it with:

component: Components.HomeComponent

And also in your admin.module.ts file this:

entryComponents: [Components.HomeComponent],

is redundant. Router does it internally.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to stop function from appComponent into homeComponent. Angular2

From Dev

Angular 2 Component Factory Resolver Helper Function

From Dev

Angular2: No Pipe decorator found on Component

From Dev

Angular2: No Pipe decorator found on Component

From Dev

Call nested component function angular2

From Java

angular2 call function of parent component

From Java

Angular Unit Test Error: No component factory found for Component. Did you add it to @NgModule.entryComponents

From Dev

calling parent component function from router component in angular2

From Dev

Angular4 : Failed to compile: Argument type {path: string, component HomeComponent}[] is not assignable to parameter type Routes

From Dev

Angular2 Router: Cannot find primary outlet to load 'HomeComponent'

From Dev

Angular2 Router: Cannot find primary outlet to load 'HomeComponent'

From Java

Angular 4: no component factory found,did you add it to @NgModule.entryComponents?

From Java

Angular2: child component access parent class variable/function

From Java

Angular2 component's "this" is undefined when executing callback function

From Java

Angular2 - how to call component function from outside the app

From Dev

Angular2 Component inside ngFor throws Error (viewFactory is not a function)

From Dev

Binding function result to Angular2 component (TypeScript)

From Dev

dart angular2 - function in sub-component

From Dev

Invoke Angular2 Component function from VisJS Event

From Dev

Angular2 - pass variable with EventEmitter by timeout function to parent component

From Dev

How to reference a variable of the component in a function not called in angular2/4?

From Dev

Vue component v-for with factory function

From Dev

angular.factory is not a function

From Dev

Angular invoke a factory function within the same factory

From Dev

angular2 final release ng-bootstrap component not found 404

From Dev

Latest builds from Angular2 complain with: NgModule DynamicModule uses HomeComponent via "entryComponents"

From Dev

self.context is not a function in Angular2 when calling a component function

From Dev

Angular 2 component function call

From Dev

Angular js Factory call "is not a function"

Related Related

  1. 1

    How to stop function from appComponent into homeComponent. Angular2

  2. 2

    Angular 2 Component Factory Resolver Helper Function

  3. 3

    Angular2: No Pipe decorator found on Component

  4. 4

    Angular2: No Pipe decorator found on Component

  5. 5

    Call nested component function angular2

  6. 6

    angular2 call function of parent component

  7. 7

    Angular Unit Test Error: No component factory found for Component. Did you add it to @NgModule.entryComponents

  8. 8

    calling parent component function from router component in angular2

  9. 9

    Angular4 : Failed to compile: Argument type {path: string, component HomeComponent}[] is not assignable to parameter type Routes

  10. 10

    Angular2 Router: Cannot find primary outlet to load 'HomeComponent'

  11. 11

    Angular2 Router: Cannot find primary outlet to load 'HomeComponent'

  12. 12

    Angular 4: no component factory found,did you add it to @NgModule.entryComponents?

  13. 13

    Angular2: child component access parent class variable/function

  14. 14

    Angular2 component's "this" is undefined when executing callback function

  15. 15

    Angular2 - how to call component function from outside the app

  16. 16

    Angular2 Component inside ngFor throws Error (viewFactory is not a function)

  17. 17

    Binding function result to Angular2 component (TypeScript)

  18. 18

    dart angular2 - function in sub-component

  19. 19

    Invoke Angular2 Component function from VisJS Event

  20. 20

    Angular2 - pass variable with EventEmitter by timeout function to parent component

  21. 21

    How to reference a variable of the component in a function not called in angular2/4?

  22. 22

    Vue component v-for with factory function

  23. 23

    angular.factory is not a function

  24. 24

    Angular invoke a factory function within the same factory

  25. 25

    angular2 final release ng-bootstrap component not found 404

  26. 26

    Latest builds from Angular2 complain with: NgModule DynamicModule uses HomeComponent via "entryComponents"

  27. 27

    self.context is not a function in Angular2 when calling a component function

  28. 28

    Angular 2 component function call

  29. 29

    Angular js Factory call "is not a function"

HotTag

Archive