Search code examples
angularvisual-studio-codeangular2-routingangular2-template

Template is not rendering in Angular2


I want to render html template by giving url in Angular2, But template is not loading. I am using visual studio code editor, Below is my code and structure.

enter image description here

import {Component} from 'angular2/core';
import {LoginComponent} from '../Login/login.component'

@Component({
    selector: 'my-app',
    // template: '<h1>Yash Employees</h1><login></login>',
    templateUrl: './app.html',
    directives: [LoginComponent]
})
export class AppComponent { }

template attribute is working, But templateUrl is not.

app.html contains only single line,

<h1>hi</h1>

What I need to change to resolve this?


Solution

  • Use Urls for your templateUrl properties as below,

    @Component({
        selector: 'my-app',
        templateUrl: './app/component/app/app.html',
        directives: [LoginComponent]
    })
    

    Update : As per the documentation ./filename should work but in your case you say that it is not working I wounder.

    Reference: enter image description here