angular-cn/public/docs/js/latest/api/di_annotations/Optional-class.jade

33 lines
731 B
Plaintext

p.location-badge.
exported from <a href="/angular2/di_annotations.html">angular2/di_annotations</a>
defined in <a href="https://github.com/angular/angular/tree/master/modules/angular2/src/di/annotations.js#L77">angular2/src/di/annotations.js (line 77)</a>
:markdown
A parameter annotation that marks a dependency as optional. <a href='../di/Injector-class.html'><code>Injector</code></a> provides `null` if the dependency is not
found.
```
class AComponent {
constructor(@Optional() aService:MyService) {
this.aService = aService;
}
}
```
.l-main-section
h2 Members
.l-sub-section
h3 constructor
pre.prettyprint
code.
constructor()
:markdown