- Essential Angular
- Victor Savkin Jeff Cross
- 218字
- 2021-07-02 22:56:26
How is it possible?
Why did not we do it before, in Angular 1? To make AOT work the application has to have a clear separation of the static and dynamic data in the application. And the compiler has to built in such a way that it only depends on the static data. When designing and building Angular we put a lot of effort to do exactly that. And such primitives as classes and decorators, which the new versions of JavaScript and TypeScript support, made it way easier.
To see how this separation works in practice, let's look at the following example. Here, the information in the decorator is known statically. Angular knows the selector and the template of the talk component. It also knows that the component has an input called talk and an output called rate. But the framework does not know what the constructor or the onRate function do.
@Component({
selector: 'talk-cmp',
template: `
{{talk.title}} {{talk.speaker}}
Rating: {{ talk.rating | formatRating }}
<watch-button [talk]="talk"></watch-button>
<rate-button [talk]="talk" (click)="onRate()"></rate-button>
`
})
class TalkCmp {
@Input() talk: Talk;
@Output() rate: EventEmitter;
constructor() {
// some initialization logic
}
onRate() {
// reacting to a rate event
}
}
Since Angular knows all the necessary information ahead of time, it can compile this component without actually executing any application code, as a build step.
- Microsoft Exchange Server PowerShell Cookbook(Third Edition)
- 架構不再難(全5冊)
- 名師講壇:Spring實戰開發(Redis+SpringDataJPA+SpringMVC+SpringSecurity)
- C#開發案例精粹
- Python機器學習之金融風險管理
- FFmpeg開發實戰:從零基礎到短視頻上線
- 零基礎學C語言(升級版)
- Python+Office:輕松實現Python辦公自動化
- SAP Web Dynpro for ABAP開發技術詳解:基礎應用
- Java從入門到精通(視頻實戰版)
- Java核心編程
- C Primer Plus(第6版)中文版【最新修訂版】
- Java程序設計
- Learning Alfresco Web Scripts
- Unity3D高級編程:主程手記