![Hands-On Full Stack Web Development with Aurelia](https://wfqqreader-1252317822.image.myqcloud.com/cover/785/36699785/b_36699785.jpg)
上QQ阅读APP看书,第一时间看更新
Dependency injection
All you need is the @autoinject annotation. The JS/HTML mapping is performed automatically by the framework:
class Ticket { /* class code, properties, methods... */ } @inject export class Sale {
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)