1

I have the following Angular plnkr.co: https://plnkr.co/edit/xA8jU4QYDGxzohNg5NFj?p=preview.

//app.component.ts

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

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html'
})
export class AppComponent { name = 'Angular'; }

//app.component.html

testing...
<router-outlet></router-outlet>

The oputput in the browser is:

Loading AppComponent content here ...

Why doesn't it see the app.component.html file? Or is this some other issue?

5 Answers 5

3

Try like this :

add below line your app.module.ts

import { NgModule, CUSTOM_ELEMENTS_SCHEMA  } from '@angular/core';

@NgModule({
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})

plnkr demo

Sign up to request clarification or add additional context in comments.

4 Comments

That works but why is it needed? None of my files have a hyphen in their name.
schemas: [ CUSTOM_ELEMENTS_SCHEMA ] need to be added to each component where you are using custom HTML tags.
I see. When I use app-root, I can remove CUSTOM_ELEMENTS_SCHEMA.
Does not work, In my app-root component html, I call 3 component by selector tag, but the app-root html does not render at all.
1

Your app.component.html contains <router-outlet></router-outlet> but there are no child routes defined. This is causing the issue.

In order to fix this, either you need to remove router-outlet from app.component.html or you should define child route config in app.router.ts.

Working Example: https://plnkr.co/edit/wbW1s8PqDtu35GR8HC8D?p=preview

Visit Angular Guide for routes to read more about routing config and child routes.

1 Comment

I don't see app.router.ts. Also, you include route.html, which is not there either. Why not just use app.component.html?
0

Here you were missing correct routing implementation several errors are there in console please refer to them.

app.component.html:

testing...
<div routeLink="x" routerLinkActive="active">
  Click
</div>
<router-outlet></router-outlet>

app.route.ts:

    import {Component, NgModule} from '@angular/core';
import { RouterModule, Routes } from '@angular/router';


@Component({
  selector: 'x',
  templateUrl: './route.html'
})

export class X{

}


const routes1: Routes = [
    {path : '', redirectTo: '/x', pathMatch: 'full'},
    {path : 'x', component: X}
  ]

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

}

Please find working example very close to your requirement below: https://plnkr.co/edit/xA8jU4QYDGxzohNg5NFj?p=preview

1 Comment

I see this in the HTML output: "Loading AppComponent content here ..."
0

It did not work for me, try this one:

src/app/app.module.ts

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, FormsModule, HttpClientModule],
  bootstrap: [AppComponent],
})
export class AppModule {}

from this helpful link: https://malcoded.com/posts/why-angular-not-works/

Comments

0

app.component.ts

import { Component } from '@angular/core';
        
@Component({
        selector: 'app-root',
        templateUrl: './app.component.html',
        styleUrls: ['./app.component.css']
})
export class AppComponent {
        title = 'app';
}

app.component.html

<router-outlet></router-outlet>

Please write the below code in the index.html

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Myapp</title>
    <base href="/">
        
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" type="image/x-icon" href="favicon.ico">
  </head>
  <body>
    <app-root></app-root>  
  </body>
</html> 

1 Comment

How does changing the selector make any difference? Also, I'm working app.component.html. Not index.html.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.