模板未在 Angular2 中呈现

Template is not rendering in Angular2

我想通过在 Angular2 中提供 url 来渲染 html 模板,但是模板没有加载。我正在使用 visual studio 代码编辑器,下面是我的代码和结构。

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 属性有效,但 templateUrl 无效。

app.html 只包含一行,

<h1>hi</h1>

我需要更改什么来解决这个问题?

为您的 templateUrl 属性使用 Urls,

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

更新:根据 documentation ./filename 应该可以工作,但在你的情况下你说它不工作我很受伤。

参考:

我遇到这个问题是因为我对该路由应用了防护。 移除那个防护后它工作正常