- 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.
- LabVIEW Graphical Programming Cookbook
- The Android Game Developer's Handbook
- SpringMVC+MyBatis快速開發(fā)與項目實戰(zhàn)
- Vue.js入門與商城開發(fā)實戰(zhàn)
- Java開發(fā)入行真功夫
- Visual Basic學(xué)習(xí)手冊
- Learning Hunk
- Raspberry Pi Home Automation with Arduino(Second Edition)
- Corona SDK Mobile Game Development:Beginner's Guide(Second Edition)
- Mastering Unity 2D Game Development(Second Edition)
- Geospatial Development By Example with Python
- Python機器學(xué)習(xí)之金融風(fēng)險管理
- Go語言從入門到精通
- Python機器學(xué)習(xí)與量化投資
- Java程序設(shè)計教程