angular-cn/public/docs/js/latest/api/di/OptionalAnnotation-class.jade

36 lines
707 B
Plaintext

p.location-badge.
exported from <a href='../di'>angular2/di</a>
defined in <a href="https://github.com/angular/angular/tree/3a0410a/modules/angular2/src/di/annotations_impl.ts#L57-L76">angular2/src/di/annotations_impl.ts (line 57)</a>
:markdown
A parameter annotation that marks a dependency as optional. <a href='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 toString
pre.prettyprint
code.
toString()
:markdown