メインコンテンツまでスキップ
バージョン: v4.38

Ember

It's recommended to use the getting started docs for creating a Stencil project using the native Stencil tooling. This way, in your Ember project, you don't need to configure anything extra, and you can use Stencil components natively.

For example, if using the Ionic Framework in your Ember project:

  1. Add the Ionic Framework to your app:
npm install @ionic/core
  1. Install the components from the library:
app/app.js
import '@ionic/core'; // installs all the components from Ionic Framework
  1. Use the components anywhere:
app/components/example.gjs
<template>
<ion-toggle></ion-toggle>
</template>
  1. You can hook up events / state (controlled component pattern):
app/components/example-with-state.gjs
import { on } from '@ember/modifier';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';

export default class Demo extends Component {
<template>
<ion-toggle checked="{{this.isOn}}" {{on "ionChange" this.toggle}}></ion-toggle>
</template>

@tracked isOn = true;

toggle = () => this.isOn = !this.isOn;
}

Live Demo (using Ionic from a CDN)

Legacy​

EmberでStencilコンポーネントを操作するのは、ember-cli-stencilアドオンのおかげでとても簡単です。アドオンは次の処理を行います。

  • 必要なファイルをvendor.jsにインポートする
  • コンポーネントの定義をassetsディレクトリにコピーする
  • オプションで、古いEmberのバージョンと互換性を向上させるラッパーコンポーネントを作成する

まず初めに、Emberのアドオンをインストールします。

ember install ember-cli-stencil

そして、アプリケーションをビルドすると、依存するStencilコレクションが自動的に検出され、アプリケーションに含まれます。そのため、hbsファイルでCustom Elementを使うだけで、追加の作業は必要ありません。詳細は、ember-cli-stencilのドキュメントをご覧ください。

NOTE: ember-cli-stencil hasn't kept up with ember's evolution and will not work in newer ember apps.