【发布时间】:2018-05-22 11:50:25
【问题描述】:
我从聚合物 3 开始,我正在编写本教程 https://www.polymer-project.org/1.0/start/first-element/step-5,所以基本上我的组件 js 文件如下
icon-toggle.js
import { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
import '@polymer/iron-icon/iron-icon.js';
class IconToggle extends PolymerElement {
static get template() {
return html`
<style>
/* shadow DOM styles go here */
:host {
display: inline-block;
--icon-toggle-color: lightgrey;
--icon-toggle-outline-color: black;
--icon-toggle-pressed-color: red;
}
iron-icon {
fill: var(--icon-toggle-color, rgba(0,0,0,0));
stroke: var(--icon-toggle-outline-color, currentcolor);
cursor: pointer;
}
:host([pressed]) iron-icon {
fill: var(--icon-toggle-pressed-color, currentcolor);
}
</style>
<!-- shadow DOM goes here -->
<iron-icon icon="[[toggleIcon]]"></iron-icon>
`;
}
static get properties() {
return {
pressed: {
type: Boolean,
value: false,
notify: true,
reflectToAttribute: true
},
toggleIcon: {
type: String
}
};
}
constructor() {
super();
this.addEventListener('click', this.toggle.bind(this));
}
toggle() {
this.pressed = !this.pressed;
}
}
customElements.define('icon-toggle', IconToggle);
现在我想知道如何导入它并在 Angular 5 应用程序中使用它。
【问题讨论】:
-
将其作为模块导入
index.html并将标签放置在页面中的任何位置。如果您想将它放在任何组件中,请查看 ngmodule 的entryComponents:[]。
标签: angular5 web-component polymer-3.x