2016-12-07 64 views
1

我初學者角2角2項目中使用NPM包,我們可以在角2個項目通過導入如下如何使用涼亭組成的角2項目

import { FormsModule } from '@angular/forms'; 

也使用它們,我們可以使用package.json文件導入並安裝npm包。

但問題是我必須在我的angular 2項目中導入bower組件。 這是使用該bower componenthttps://www.predix-ui.com/?show=getting_started&type=local

我複製了涼亭的部件置入資產的文件夾在我的項目,並試圖導入涼亭組件在我index.html如下

<head> 
    <meta charset="utf-8"> 
    <title>TestApp</title> 
    <base href="/"> 
    <link rel="import" href="./assets/px-spinner/px-spinner.html" /> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="icon" type="image/x-icon" href="favicon.ico"> 
</head> 
的鏈接,安裝和指南

然後我嘗試在我的app.component.html文件中使用它們,該文件位於我的src/app中,如下所示。

<h1> 
    {{title}} 
</h1> 
<px-spinner> 
    <px-inbox height="100vh" list-items='[{"id":"1","title":"GT Vibration","subtitle":"Block 2","severity":"important","date":"2016-10-05T01:29"}]'> 
    // define or bind to your details view here 
    </px-inbox> 

</px-spinner> 

但它會給出以下錯誤。

zone.js:388Unhandled Promise rejection: Template parse errors: 
'px-inbox' is not a known element: 
1. If 'px-inbox' is an Angular component, then verify that it is part of this module. 
2. If 'px-inbox' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. (" 
</h1> 
<link rel="import" href="./assets/px-spinner/px-spinner.html" /> 
[ERROR ->]<px-inbox height="100vh" list-items='[{"id":"1","title":"GT Vibration","subtitle":"Block 2","severity"): [email protected]:0 ; Zone: <root> ; Task: Promise.then ; Value: Error: Template parse errors:(…) Error: Template parse errors: 
'px-inbox' is not a known element: 
1. If 'px-inbox' is an Angular component, then verify that it is part of this module. 
2. If 'px-inbox' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. (" 
</h1> 
<link rel="import" href="./assets/px-spinner/px-spinner.html" /> 
[ERROR ->]<px-inbox height="100vh" list-items='[{"id":"1","title":"GT Vibration","subtitle":"Block 2","severity"): [email protected]:0 
    at TemplateParser.parse (http://127.0.0.1:4200/main.bundle.js:13787:19) 
    at RuntimeCompiler._compileTemplate (http://127.0.0.1:4200/main.bundle.js:32817:51) 
    at http://127.0.0.1:4200/main.bundle.js:32737:62 
    at Set.forEach (native) 
    at RuntimeCompiler._compileComponents (http://127.0.0.1:4200/main.bundle.js:32737:19) 
    at createResult (http://127.0.0.1:4200/main.bundle.js:32633:19) 
    at ZoneDelegate.invoke (http://127.0.0.1:4200/main.bundle.js:62681:26) 
    at Zone.run (http://127.0.0.1:4200/main.bundle.js:62563:43) 
    at http://127.0.0.1:4200/main.bundle.js:62951:57 
    at ZoneDelegate.invokeTask (http://127.0.0.1:4200/main.bundle.js:62714:35) 

現在我很困惑如何在我的項目中使用它們。請給我一個提示。

感謝

+0

可你的jsfiddle添加以下? –

回答

3

我猜你正在尋找的東西是這樣的:

schemas: [CUSTOM_ELEMENTS_SCHEMA] 

@NgModule

Plunker Example

+0

非常感謝。它正在工作。 –

0

webcomponents-lite.js填充工具中是一個先決條件according to the readme of px-spinner

添加index.html中

<script src="bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>