2017-09-01 201 views
0

我有一個角2應用程序,我在觀看視頻教程時正在構建。但問題是我很好地引用了這些文件,但我在瀏覽器的控制檯中找不到頁面。 這裏是我的組件爲什麼我的角度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被正確引用的代碼,但我仍然得到頁NOF發現錯誤。請任何幫助將非常歡迎。謝謝。 UPDATE:結構工程 enter image description here

+0

你可以發佈你的項目結構嗎? –

+0

我剛做粗略的更新找不到更好的方式來更新項目結構。 – Izuagbala

+0

我正在談論項目結構的截圖。 –

回答

1

你好能不能請你:

templateUrl: './employee.component.html' 

這是路徑問題。您不需要在teamplateURL中添加員工

下面是完整的代碼:

@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() { 
    } 
} 
+0

您好@Izuagbala,如果您使用此解決方案得到解決,請將答案標記爲已接受。 –

+0

我試過你發佈的解決方案,但問題仍然存在。我得到 http:// localhost:59956/src/app/Employee/employee.component.html 404(Not Found) http:// localhost:59956/src/app/Employee/employee.component.html;區域:;任務:Promise.then;值:無法加載http:// localhost:59956/src/app/Employee/employee.component.html undefined – Izuagbala

+0

感謝您的回答有幫助。我現在已經解決了這個問題。 – Izuagbala

1

由於employee.component.html和employee.component.ts都在同一個文件夾,然後無需添加僱員/ employee.component.html模板URL路徑。你也只使用'。'在文件夾名稱之前,請將其更改爲'./employee.component.html'。希望ut會起作用。

相關問題