0

I'm upgrading my application from the beta.11 to the RC3. But I have a problem with a component I used in the beta.11 version.

Basically, I created a modular component "MyMessage", which is a angular2 component (and not a NgModule). I use this module in a page component "MessagesPage".

Here is what was working with the beta.11 :

@Component({
  selector: 'my-message',
  templateUrl: 'my-message.component.html',
})
export class MyMessage {
  // ... 
}

import { MyMessage } from '../components/my-message.component';
@Component({
  templateUrl: 'messages.html' // Template contains <my-message> tags
  //, directives: [ MyMessage ]
})
export class MessagesPage {
  messages: Array<MyMessage>;
  // ...
}

But I have a dependency problem :

Cannot find name 'MyMessage'

So I tried to move my 'MyMessage' component to a NgModule, which seemed to be the solution.

import { MyMessage } from './components/my-message.component';
@NgModule({
  imports:      [ IonicModule.forRoot(MyMessage) ],
  declarations: [ MyMessage ]
})
export class MyMessageModule { }

And in the app.module.ts, I added MyMessageModule in the imports section. But I still have the previous error, I don't understand what I missed.

Thanks !

Julian Le Calvez
  • 453
  • 7
  • 27

1 Answers1

0

Change your MyMessageModule as below :

import { MyMessage } from './chat-message.component';
@NgModule({
  declarations: [ MyMessage ],
  exports : [ MyMessage ]
})
export class MyMessageModule { }
ranakrunal9
  • 13,320
  • 3
  • 42
  • 43
  • thank you ! I tried that but I still have the problem. I also tried to remove all my calls to this module, but keep only one in a template, but I got this error in the javascript console : Unexpected directive 'MyMessage' imported by the module 'MyMessageModule' – Julian Le Calvez Nov 24 '16 at 09:44
  • You have to remove `MyMessage` from `imports` decorator metadata of `MyMessageModule` – ranakrunal9 Nov 24 '16 at 10:00
  • Ok it works. I'm lost with all these decorator metadata. Last question : I load and fill in my component from the typescript classes, but it seems that my class is not exported everywhere because this line fails : `messages: Array;` (`Cannot find name 'MyMessage'`) – Julian Le Calvez Nov 24 '16 at 10:11
  • set `messages` like `messages: MyMessage[];` – ranakrunal9 Nov 24 '16 at 10:14
  • doesn't work either :( it works when I import it manually (i don't think it's the best way but at least it works) – Julian Le Calvez Nov 24 '16 at 10:18
  • actually I don't have the errors anymore, but my tags in templates are not replace. I still have them in the DOM. – Julian Le Calvez Nov 24 '16 at 10:32