簡體   English   中英

Angular2:通過指令將外部Component注入其他組件無效

[英]Angular2: Inject external Component into other component via directive not working

我希望子組件模板加載到父組件模板中。 (由於缺乏更好的措辭,我稱之為孩子和父母)

這是我的孩子:

import {Component,Directive, ElementRef, Input} from '@angular/core';
import {IONIC_DIRECTIVES} from 'ionic-angular';


@Component({ 
  selector: '[parentselector]',
  template: '<div>I AM A CHILD</div>',
  directives: [IONIC_DIRECTIVES] 
})


export class ChildPage {
    constructor() {

    }
}

這是我的父母:

@Component({
    templateUrl: 'build/pages/parent/parent.html',
    directives: [ChildPage]
})

和父母的HTML:

<ion-content>
    <ion-slides>
        <ion-slide><parentselector>Parent To Be Overriden</parentselector>
        </ion-slide>
    </ion-slides>
</ion-content>

有什么想法錯了嗎?

Angular 2 Cheat Sheet (搜索選擇器)中可以看出,通過使用括號,您可以限制調用指令的位置。 例如:

selector:'[parentselector]' - means you can only select as an attribute
selector:'parentselector' - means you can only select as an element
selector:'.parentselector' - means you can only select as a css class

所以如果你脫掉[]一切都應該好

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM