typescript – Angular2:通过指令将外部Component注入其他组件不工作

前端之家收集整理的这篇文章主要介绍了typescript – Angular2:通过指令将外部Component注入其他组件不工作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我希望子组件模板加载到父组件模板中. (由于缺乏更好的措辞,我称之为孩子和父母)

这是我的孩子:

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

所以如果你脱掉[]一切都应该好

@H_403_43@

猜你在找的Angularjs相关文章