ionic-framework - "ion-button + icon-only"内部组件不工作

标签 ionic-framework ionic3

我正在使用 Ionic 3.*,创建一个仅包含一个按钮的组件。

组件代码为:

@Component({
  selector: 'profile-button',
  templateUrl: 'profile-button.html',
})
export class ProfileButtonComponent {
  constructor(
    private popoverCtrl: PopoverController
  ) {}

  /**
   * Present the Profile popover
   * @param ev
   * @returns {Promise<any>}
   */
  async presentPopover(ev) {
    let popover = this.popoverCtrl.create(ProfilePopover);

    return popover.present({
      ev
    });
  }
}

我的模板是:
<button ion-button icon-only (click)="presentPopover($event)" title="Profile">
    <ion-icon name="person"></ion-icon>
</button>

问题:

问题是 icon-only指令只是被忽略。该按钮仍然具有背景颜色。
如果我将模板放在组件之外,它会显示正确的样式。

看起来指令在组件中不可用。我的组件在自定义模块内,而不是在 AppModule 上。

我该如何解决这个问题?发现在 Ionic2 上我需要手动导入指令,但它不适用于 Ionic3。

最佳答案

我在 another S.O. thread 上找到了解决方案.

在你的 *.module.ts 添加 IonicModule进入 imports部分。

@NgModule({
  imports: [
    CommonModule,  // <-- standard Angular module
    IonicModule    // <-- standard ionic module
  ], ...
})

关于ionic-framework - "ion-button + icon-only"内部组件不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44787367/

相关文章:

angular - Ionic 3文件夹结构

angular - 从源 'API_URL' 访问 'http://localhost:8080' 处的 XMLHttpRequest 已被 CORS 策略 : 阻止

javascript - 判断滑动事件是左滑动还是右滑动

ionic-framework - Ionic - 如何滑动 ionic 段?

angular - ngx-datatable - 编辑单元格并弹出一个新按钮来保存更改

node.js - socket.io 客户端在 ionic 应用程序中给出 cors 错误

angular - 自定义 404 页面 Ionic 3

android - Ionic - 自定义字体不加载

javascript - 谷歌地图和异步 javascript

mysql - 在 Cordova/Ionic 应用程序中通过 USB 在桌面移动设备之间同步数据