簡體   English   中英

如何使用ionic2制作自定義元素組件?

[英]How to make a custom element component with ionic2?

我定義了一個登錄按鈕組件,如下所示:

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

@Component({
  selector: 'login-button',
  template:
    `<ion-buttons end>
      <button ion-button round (click)="openLogin()">
        Login
        <ion-icon name="arrow-up"></ion-icon>
      </button>
    </ion-buttons>
    <ng-content></ng-content>
    `
})

export class LoginButton {

  constructor() {
    console.log('Hello LoginButton');
  }
}

app.module.ts其注冊為提供程序,然后在html文件中使用它:

<ion-content padding>
</ion-content>
<ion-footer>
  <ion-navbar>
    <button ion-button icon-only menuToggle>
      <ion-icon name="menu"></ion-icon>
    </button>
    <ion-title>
      Fragen
    </ion-title>

    <login-button></login-button>
  </ion-navbar>
</ion-footer>

沒有錯誤訊息。 調用了構造函數,但是模板未填充到元素中。 顯然,缺少一個步驟。 哪一個?

無需將其注冊為provider ,而將其注冊為declarationsentryComponents下的entryComponents

然后可以使用selector顯示按鈕: <login-button></login-button> (無需顯式導入)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM