官术网_书友最值得收藏!

  • Essential Angular
  • Victor Savkin Jeff Cross
  • 132字
  • 2021-07-02 22:56:26

Trade-offs

Since AOT is so advantageous, we recommend to use it in production. But, as with everything, there are trade-offs. For Angular to be able to compile your application ahead of time, the metadata has to be statically analyzable. For instance, the following code will not work in the AOT mode:

@Component({
selector: 'talk-cmp',
template: () => window.hide ? 'hidden' : `
{{talk.title}} {{talk.speaker}}
Rating: {{ talk.rating | formatRating }}
<watch-button [talk]="talk"></watch-button>
<rate-button [talk]="talk" (click)="onRate()"></rate-button>
`
})
class TalkCmp {
//...
}

The window.hide property will not be defined. So the compilation will fail to point out the error. A lot of work has been done to make the compiler smarter, so it can understand most of the day-to-day patterns you would use when building your application. But certain things will never work, like the preceding example.

主站蜘蛛池模板: 富宁县| 定南县| 定州市| 莒南县| 乳山市| 乌海市| 邵东县| 乾安县| 佛学| 宣城市| 富蕴县| 安乡县| 手游| 德清县| 湄潭县| 清流县| 隆昌县| 肃北| 临朐县| 綦江县| 福海县| 湾仔区| 吴桥县| 灵石县| 庄浪县| 文成县| 雷州市| 鲁甸县| 望都县| 阜新市| 平遥县| 河东区| 靖州| 商都县| 体育| 台南市| 余庆县| 桐柏县| 宜阳县| 三江| 渭南市|