2016-11-21 15 views
0

我想使用Ng-內容,它似乎不工作。完整的代碼在這裏plunker Full codeAngular 2 Ng-內容,它似乎不工作

@Component({ 
    selector: 'my-app', 
    template: ` 
    <div> 
     <h2>Hello {{name}}</h2> 
     <div> 
     Title: 
     <ng-content select=".my-component-title"></ng-content> 
     </div> 
     <div> 
     Content: 
     <ng-content select=".my-component-content"></ng-content> 
     </div> 
    </div> 
    `, 
}) 

我已經更新了plunker碼現在NG-內容是不是在根組件。但它仍然沒有工作。

回答

1

<ng-content>不支持根組件。

<ng-content>僅跨越Angular2組件中定義的元素和組件。

又見Angular2 root component with <ng-content>

+0

我有更新plunker代碼,現在NG-內容不是根 – balaG

+0

但也沒有什麼配套的選擇。目前還不清楚你的問題是什麼。預期的行爲是什麼? –