为什么ng-content不能正常工作?

时间:2018-04-07 01:22:36

标签: javascript angular

我在演示中使用ng-content,但我的innerHTML没有显示。为什么内部内容没有显示?

这是我的代码 https://stackblitz.com/edit/angular-lav42u

@Component({
  selector: 'hello',
  template: `
  <h4 class="card-title">
    <ng-content select=".setup"></ng-content>
  </h4>
  `,
  styles: [`h1 { font-family: Lato; }`]
})

1 个答案:

答案 0 :(得分:0)

这是因为你的select正在寻找一个具有类setup的元素,除非它回答了这个条件,否则不会投射任何其他元素。您必须删除select=".setup",才能投放<p><hello>内的AppComponent元素,或将setup类添加到该元素。

enter image description here