【问题标题】:Why is my angular 2 application not rendering?为什么我的 Angular 2 应用程序不呈现?
【发布时间】:2017-09-01 04:30:48
【问题描述】:

我在观看视频教程时正在构建一个 Angular 2 应用程序。但问题是我很好地引用了这些文件,但在浏览器的控制台中找不到页面。 这是我的组件的代码

@Component({
   moduleId: module.id,
   selector: 'my-employee',
   templateUrl: '.Employee/employee.component.html'
})
export class EmployeeComponent {
   firstName: string = 'Mr X';
   lastName: string = 'Johnson';
   gender: string = 'Male';
   age: number = 20;
}

templateUrl 被正确引用,但我仍然收到 page nof found 错误。请任何帮助将受到高度欢迎。谢谢。 更新:项目结构

【问题讨论】:

  • 你能发布你的项目结构吗?
  • 我只是做了粗略的更新找不到更好的方法来更新项目结构。
  • 我说的是项目结构截图。
  • 刚刚上传了。
  • 请查看已发布的答案,如果仍然遇到任何问题,请在答案的评论中发布。

标签: angular angular2-template angular2-components


【解决方案1】:

你好,可以试试吗:

templateUrl: './employee.component.html'

这是路径问题。您无需在teamplateURL 中添加Employee

这是完整的代码:

@Component({
    moduleId: module.id,
    selector: 'my-employee',
    templateUrl: './employee.component.html'
})
export class EmployeeComponent {
    firstName: string = 'Mr X';
    lastName: string = 'Johnson';
    gender: string = 'Male';
    age: number = 20;

    constructor() {
    }
}

【讨论】:

【解决方案2】:

由于employee.component.html 和employee.component.ts 在同一个文件夹中,因此无需在模板url 路径中添加Employee/employee.component.html。你也只使用'。'在文件夹名称之前,因此只需将其更改为 './employee.component.html'。希望 ut 会起作用。

【讨论】:

    猜你喜欢
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 2020-08-27
    • 2020-09-05
    • 1970-01-01
    • 2012-05-02
    • 2022-01-01
    • 2022-10-15
    相关资源
    最近更新 更多