1

I have created a new component for Angular but I can't see the html rendered. Instead of the html rendered I've got the route to the html.

These are my folder structure:

enter image description here

This is the component created by me called server.component.ts:

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

@Component({
    selector: 'app-server',
    template: './server.component.html'
})
export class ServerComponent {

}

This is the html of the component, server.component.html:

<p>Este es mi nuevo componente!!!</p>

In app.component.html is where I include the tag of my component :

<div>
    <input type = "text" [(ngModel)] = "message" />
    <p>{{message}}</p>
    <hr>
    *<app-server></app-server>*
</div>

And this is my app.module.ts code where I import ServerComponent to use it later:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';


import { AppComponent } from './app.component';
import { ServerComponent } from './server/server.component';

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

And this is the result that I get in my browser:

enter image description here

What am I doing wrong?

2 Answers 2

5

replace template by templateUrl in your component definition, it should be

@Component({
    selector: 'app-server',
    templateUrl: './server.component.html'
})
Sign up to request clarification or add additional context in comments.

Comments

1

In the server.component.ts you have used template attribute which requires you to pass a template between the . You need to use templateUrl attribute if you want to pass the link to a template.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.