当前位置: 动力学知识库 > 问答 > 编程问答 >

Angular2 - Multi-Content with downgraded ng2-component

问题描述:

Im trying to upgrade our ng1 project to ng2 with angular-upgrade mechanism. Actually i rewrite a component, that provide multiple-content (in angular 1.5 multiple-transclusion / slots).

My question is, its possible to use multi-content in a component, that will downgrade to use it in ng1 environment.

I try this since yesterday to get it work. It works if i using one ng-content element, but if i try to use two or nore ng-content, i getting always an error that i use x ng-content but 1 slot is provided.

My Component look like

@Component({

selector: NgContentTest.UPGRADE_ELEMENT_NAME,

template: `

<div>

<div style="background-color:red ">

<ng-content select="[con1]"></ng-content>

</div>

<div style="background-color: yellow; display: block;height: 55px;">

<ng-content select="[cont2]"></ng-content>

</div>

</div>

`

})

export class NgContentTest {

static UPGRADE_ELEMENT_NAME = 'ngContentTest';

}

Consumer is a ng1 directive with following template example:

<ng-content-test>

<div cont1>

Content - 1

</div>

<div cont2>

Content - 2

</div>

</ng-content-test>

Error:

The component NgContentTest has 2 elements, but only 1 slots were provided.

分享给朋友:
您可能感兴趣的文章:
随机阅读: