Update: Solved, just need to add IonicModule for imports in @NgModule. Code below fixed. Maybe it will be useful for someone.
Hi guys.
I try to rewrite my component from beta-11 to separate module on rc.1 and got an error.
My component uses ion-icon.
My code example:
notify.component.ts
'use strict';
import {Component, OnDestroy, ElementRef} from '@angular/core';
import {NotifyService} from './notify.service';
@Component({
selector: 'notify',
template: `
<div *ngFor="let item of notifications; let i = index"
ngClass="{{item.classes}}"
class="notify">
<ion-icon name="md-close-circle"
class="close-icon"
(click)="close(i)"></ion-icon>
<div [innerHtml]="item.text"></div>
</div>
`
})
export class NotifyComponent implements OnDestroy {
private updateNotificationEmmiter: any;
public notifications: [{
classes: string;
text: string;
}];
public id: string;
constructor(
private notify: NotifyService,
private elementRef: ElementRef
) {
this.id = this.elementRef.nativeElement.getAttribute('for');
this.updateNotificationEmmiter = this.notify.subscribe(() => {
this.notifications = this.notify.get(this.id);
});
}
close(i) {
this.notify.clear(this.id, i);
}
ngOnDestroy() {
this.updateNotificationEmmiter.unsubscribe();
}
}
notify.module.ts
import { NgModule } from '@angular/core';
import { IonicApp, IonicModule, Icon } from 'ionic-angular';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { NotifyComponent } from './notify.component';
import { NotifyService } from './notify.service';
@NgModule({
declarations: [
NotifyComponent,
],
imports: [
CommonModule,
IonicModule
],
exports: [
NotifyComponent,
],
entryComponents: [
NotifyComponent
],
providers: [NotifyService],
})
export class NotifyModule {}
I add NotifyModule to âimportsâ array in my AppModule (NgModule decorator) . My app transpilled without error, but in browser console I see:
runtime_compiler.js:353 Uncaught Error: Could not compile âIconâ because it is not a component.
If I comment Icon in entryComponents - I have an errror:
Template parse errors: âion-iconâ is not a known element
Also should I use IonicModule.forRoot() in imports? In NgModule faq says that I should use forChild method but IonicModule doesnât have it.
Thanks in advance for your help.