如何在 angular 2 项目中使用 bower 组件
How to use a bower component in a angular 2 Project
我是初学者 angular 2. Angular 2 项目使用 npm 包,我们可以在 angular 2 项目中使用它们,只需按如下方式导入
import { FormsModule } from '@angular/forms';
此外,我们可以使用 package.json
文件导入和安装 npm 包。
但问题是我必须在我的 angular 2 项目中导入 bower
组件。
这是 link 的安装和使用指南 bower component
(https://www.predix-ui.com/?show=getting_started&type=local)
我将 Bower 组件复制到项目中的资产文件夹中,并尝试在我的 index.html
中导入该 Bower 组件,如下所示
<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>
然后我尝试在我的 src/app
中的 app.component.html
文件中使用它们,如下所示。
<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"): AppComponent@4: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"): AppComponent@4: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)
现在我对如何在我的项目中使用它们感到困惑。请给我一个提示。
谢谢
我猜你正在寻找这样的东西:
schemas: [CUSTOM_ELEMENTS_SCHEMA]
在你的 @NgModule
webcomponents-lite.js polyfill 是先决条件according to the readme of px-spinner 。
在index.html
中添加以下内容
<script src="bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
我是初学者 angular 2. Angular 2 项目使用 npm 包,我们可以在 angular 2 项目中使用它们,只需按如下方式导入
import { FormsModule } from '@angular/forms';
此外,我们可以使用 package.json
文件导入和安装 npm 包。
但问题是我必须在我的 angular 2 项目中导入 bower
组件。
这是 link 的安装和使用指南 bower component
(https://www.predix-ui.com/?show=getting_started&type=local)
我将 Bower 组件复制到项目中的资产文件夹中,并尝试在我的 index.html
中导入该 Bower 组件,如下所示
<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>
然后我尝试在我的 src/app
中的 app.component.html
文件中使用它们,如下所示。
<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"): AppComponent@4: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"): AppComponent@4: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)
现在我对如何在我的项目中使用它们感到困惑。请给我一个提示。
谢谢
我猜你正在寻找这样的东西:
schemas: [CUSTOM_ELEMENTS_SCHEMA]
在你的 @NgModule
webcomponents-lite.js polyfill 是先决条件according to the readme of px-spinner 。
在index.html
中添加以下内容<script src="bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>