Angular中<center>的替代方案是什么?

时间:2017-09-22 14:33:24

标签: angular

Error: Template parse errors:
'center' is not a known element:
1. If 'center' is an Angular component, then verify that it is part of this module.
2. To allow any element add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("
  [ERROR ->]<center><h2>my-candid works!</h2>
  <div [style.color]="isSpecial ? 'red' : 'green'">This is style bi"): ng:///AppModule/MyCandidComponent.html@1:2

1 个答案:

答案 0 :(得分:1)

你只是想把文字集中在一起吗?

<h2 [ngStyle]="{'text-align': 'center'}">my-candid works!</h2>

或者以div为中心,您可以随时使用CSS,例如:

.yourDiv {
    margin: 0 auto;
}