2016-12-05 50 views
2

我試圖執行一個簡單的模板注入到一個頁面,但我收到在運行時出現以下錯誤中鉻的控制檯窗口:角2模板選擇不知道

zone.js:388 Unhandled Promise rejection: Template parse errors: 'recruiter-detail' is not a known element:

  1. If 'recruiter-detail' is an Angular component, then verify that it is part of this module.
  2. If 'recruiter-detail' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. ("[ERROR ->]"): [email protected]:0 ; Zone: ; Task: Promise.then ; Value: Error: Template parse errors:(…) Error: Template parse errors: 'recruiter-detail' is not a known element:
  3. If 'recruiter-detail' is an Angular component, then verify that it is part of this module.

app.component .TS

import { Component } from '@angular/core'; 
import { RecruiterDetailsComponent } from "./recruiter/recruiter-details.component"; 

@Component({ 
    selector: 'pm-app', 
    template: `<recruiter-detail></recruiter-detail>` 
}) 
export class AppComponent { 
    pageTitle: string = 'Agent details'; 

招募者-details.component.ts此駐留在子文件夾中稱爲招募者

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

@Component({ 
    selector: 'recruiter-detail', 
    templateUrl: './app/recruiter/recruiter-details.component.html' 
}) 
export class RecruiterDetailsComponent { 
} 

我正在使用VS2015。在我的wwwroot文件夾下我有一個應用程序文件夾,其中main.ts,app.component.ts和app.module.ts駐留。應用程序擁有招聘人員的子文件夾。

+1

向我們展示您的應用程序模塊,您可能已經忘記了在您的應用程序模塊中聲明RecruiterDetailsComponent – Milad

回答

1

If 'recruiter-detail' is an Angular component, then verify that it is part of this module

你有沒有在聲明段在module.ts

添加您的招聘細節部分同樣的錯誤說promise拒絕。

再次查看您的代碼,模板中可能有錯誤。

嘗試增加您的組件聲明中module.ts 如果沒有你是如何處理的承諾工作 外觀也看模板的錯誤或錯別字

+0

否我沒有。我聲明它是在app.component.ts中導入的,所以我認爲不需要。我現在將添加它,看看會發生什麼 – bilpor

+0

這已經消除了上述錯誤。我現在收到以下內容:'http:// localhost:57703/recruiter/recruiter-details.component.html 404(Not Found)' – bilpor

+0

你給你的招聘人員 - details.component .html錯誤的路徑 –

1

嘗試通過改變模板URL像

templateUrl: '應用程序/招募者/招募者-details.component.html'

代替

templateUrl:'./app/recruiter/recruiter-details.component.html'

+0

耶這種解決第二個問題。謝謝。我本可以發誓我已經試過了, – bilpor

+0

將此標記爲答案可能對某人有用。 –