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:
Patrice Chalin 2016-11-15 14:58:56 -08:00 committed by Filipe Silva
parent 4a4144efe1
commit 64bce18ea7
8 changed files with 12 additions and 8 deletions

View File

@ -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,

View File

@ -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;

View File

@ -10,6 +10,5 @@
</head>
<body>
<my-app>Loading...</my-app>
<my-providers>Loading my-providers ...</my-providers>
</body>
</html>

View File

@ -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);
}

View File

@ -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]
})

View File

@ -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

View File

@ -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;

View File

@ -22,7 +22,6 @@
<body>
<my-app>Loading my-app ...</my-app>
<my-providers>Loading my-providers ...</my-providers>
</body>
</html>