作者名:Diego Jose Argüelles Rojas Erikson Haziz Murrugarra Sifuentes
本章字?jǐn)?shù):80字
更新時(shí)間:2021-06-25 20:58:20
Dependency injection
All you need is the @autoinject annotation. The JS/HTML mapping is performed automatically by the framework:
classTicket { /* class code, properties, methods... */ }
@injectexportclassSale { constructor( ticket ) {}
public activate() {
// do something...this.ticket.toast("Sale processed!");
}
}
For Typescript users, the annotation names are very similar. Use @autoinject instead of @inject and don't forget to specify the visibility and type of object in the constructor : constructor(private ticket : Ticket)