- 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.
- 計(jì)算機(jī)網(wǎng)絡(luò)
- JavaScript+DHTML語(yǔ)法與范例詳解詞典
- 算法精粹:經(jīng)典計(jì)算機(jī)科學(xué)問(wèn)題的Python實(shí)現(xiàn)
- Python漫游數(shù)學(xué)王國(guó):高等數(shù)學(xué)、線性代數(shù)、數(shù)理統(tǒng)計(jì)及運(yùn)籌學(xué)
- 深入淺出PostgreSQL
- Python Data Analysis Cookbook
- BeagleBone Black Cookbook
- Unity 2017 Mobile Game Development
- SQL 經(jīng)典實(shí)例
- Vue.js光速入門(mén)及企業(yè)項(xiàng)目開(kāi)發(fā)實(shí)戰(zhàn)
- 進(jìn)入IT企業(yè)必讀的324個(gè)Java面試題
- 從零開(kāi)始學(xué)Selenium自動(dòng)化測(cè)試:基于Python:視頻教學(xué)版
- 軟件測(cè)試分析與實(shí)踐
- Developing Java Applications with Spring and Spring Boot
- 零基礎(chǔ)學(xué)Java(第5版)