简体   繁体   中英

Use a component in another component in ionic2

I have a component

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

@Component({
  selector: 'footer-component',
  templateUrl: 'footer.html'
})
export class FooterComponent {}

And would like to use that one in another like that

<ion-content>
  Hello
  <footer-component><footer-component/>
</ion-content>

I added both in my "@NgModule". Unfortunately I get this error :

directive_normalizer.js:92Uncaught Error: Template parse errors: Only void and foreign elements can be self closed "footer-component"

Do you know why ?

You set <footer-component><footer-component/>

Where <footer-component/> is recognized as a self closing tag (the /> ) (like <input/>

To close a tag the / should be at the beginning of the closing element. (like you see in </ion-content>

So change your <footer-component/> to </footer-component>

Full code:

<ion-content>
  Hello
  <footer-component></footer-component>
</ion-content>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM