在自定义组件

时间:2017-03-29 12:45:32

标签: angularjs angular ionic-framework ionic2

离子设置:

离子框架:2.3.0

Ionic App脚本:1.1.4

Angular Core:2.4.8

Angular Compiler CLI:2.4.8

节点:4.2.6

我是离子和角度的新手,我尝试使用离子标签创建自定义组件,看看我的代码:

mynavbar.component.ts

import {Component} from "@angular/core";
import {IONIC_DIRECTIVES} from 'ionic-angular';

@Component({
  selector: 'my-navbar',
  directives: [IONIC_DIRECTIVES],
  templateUrl: 'mynavbar.component.html'
})

export class MyNavbarComponent {}

,这是我的templateUrl:

<ion-header>
  <ion-toolbar>
    <ion-buttons start>
       <button ion-button icon-only>
         <ion-icon name="contact"></ion-icon>
       </button>
    </ion-buttons>
    <ion-title>MyApp</ion-title>
    <ion-buttons end>
       <button ion-button icon-only>
         <ion-icon name="pin"></ion-icon>
       </button>
    </ion-buttons>
  </ion-toolbar>
  <ion-segment color="primary">
    <ion-segment-button value="pessoas">
       Pessoas
    </ion-segment-button>
    <ion-segment-button value="grupos">
     Grupos
    </ion-segment-button>
  </ion-segment>
 </ion-header>

我收到此错误:没有导出的成员&IONG_DIRECTIVES&#39;。我试图导入IONIC_DIRECTIVES,因为我在这里看到一些说话者如果我们想在自定义组件中使用离子标签,那么在我们的组件中导入它,但我收到此错误。

@edit 如果我选择不导入Ionic_Directives,我没有收到任何错误,但我在自定义组件中使用的所有离子标签都会丢失所有样式

1 个答案:

答案 0 :(得分:1)

如果您使用Ionic2模板项目创建了项目,则无需导入IONIC_DIRECTIVES

IONIC_DIRECTIVES装饰器中移除directives及其条目的导入。