e2e(dependency-injection): fix for Dart and simplification for TS
Fixes #2493 No need to dual boot `AppComponent` and `ProvidersComponent` only to ensure that we could demo optional injection; instead just inject null for the `@Optional` constructor parameter type. No prose is affected by these changes.
This commit is contained in:
parent
4a4144efe1
commit
64bce18ea7
|
@ -22,7 +22,9 @@ import 'providers_component.dart';
|
|||
<button (click)="nextUser()">Next User</button>
|
||||
<p>
|
||||
<my-heroes id="authorized" *ngIf="isAuthorized"></my-heroes>
|
||||
<my-heroes id="unauthorized" *ngIf="!isAuthorized"></my-heroes>''',
|
||||
<my-heroes id="unauthorized" *ngIf="!isAuthorized"></my-heroes>
|
||||
<my-providers></my-providers>
|
||||
''',
|
||||
directives: const [
|
||||
CarComponent,
|
||||
HeroesComponent,
|
||||
|
|
|
@ -224,7 +224,11 @@ class Provider9Component implements OnInit {
|
|||
|
||||
// Sample providers 1 to 7 illustrate a required logger dependency.
|
||||
// Optional logger, can be null.
|
||||
@Component(selector: 'provider-10', template: '{{log}}')
|
||||
@Component(
|
||||
selector: 'provider-10',
|
||||
template: '{{log}}',
|
||||
providers: const [const Provider(Logger, useValue: null)]
|
||||
)
|
||||
class Provider10Component implements OnInit {
|
||||
final Logger _logger;
|
||||
String log;
|
||||
|
|
|
@ -10,6 +10,5 @@
|
|||
</head>
|
||||
<body>
|
||||
<my-app>Loading...</my-app>
|
||||
<my-providers>Loading my-providers ...</my-providers>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
import 'package:angular2/platform/browser.dart';
|
||||
|
||||
import 'package:dependency_injection/app_component.dart';
|
||||
import 'package:dependency_injection/providers_component.dart';
|
||||
|
||||
void main() {
|
||||
//#docregion bootstrap
|
||||
bootstrap(AppComponent);
|
||||
//#enddocregion bootstrap
|
||||
bootstrap(ProvidersComponent);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import { UserService } from './user.service';
|
|||
<p>
|
||||
<my-heroes id="authorized" *ngIf="isAuthorized"></my-heroes>
|
||||
<my-heroes id="unauthorized" *ngIf="!isAuthorized"></my-heroes>
|
||||
<my-providers></my-providers>
|
||||
`,
|
||||
providers: [Logger]
|
||||
})
|
||||
|
|
|
@ -53,7 +53,7 @@ import {
|
|||
{ provide: APP_CONFIG, useValue: HERO_DI_CONFIG }
|
||||
],
|
||||
// #enddocregion ngmodule-providers
|
||||
bootstrap: [ AppComponent, ProvidersComponent ]
|
||||
bootstrap: [ AppComponent ]
|
||||
})
|
||||
export class AppModule { }
|
||||
// #enddocregion ngmodule
|
||||
|
|
|
@ -229,7 +229,8 @@ let some_message = 'Hello from the injected logger';
|
|||
|
||||
@Component({
|
||||
selector: 'provider-10',
|
||||
template: template
|
||||
template: template,
|
||||
providers: [{ provide: Logger, useValue: null }]
|
||||
})
|
||||
export class Provider10Component implements OnInit {
|
||||
log: string;
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
|
||||
<body>
|
||||
<my-app>Loading my-app ...</my-app>
|
||||
<my-providers>Loading my-providers ...</my-providers>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue