2016-01-20 19:14:46 -02:00
|
|
|
// #docregion
|
2016-03-25 16:03:53 -07:00
|
|
|
import 'package:angular2/core.dart';
|
2016-01-27 15:51:50 -08:00
|
|
|
|
2016-01-20 19:14:46 -02:00
|
|
|
import 'logger_service.dart';
|
|
|
|
import 'spy_directive.dart';
|
|
|
|
|
|
|
|
@Component(
|
|
|
|
selector: 'spy-parent',
|
|
|
|
template: '''
|
|
|
|
<div class="parent">
|
|
|
|
<h2>Spy Directive</h2>
|
|
|
|
|
|
|
|
<input [(ngModel)]="newName" (keyup.enter)="addHero()">
|
|
|
|
<button (click)="addHero()">Add Hero</button>
|
|
|
|
<button (click)="reset()">Reset Heroes</button>
|
|
|
|
|
|
|
|
<p></p>
|
2016-04-30 07:01:16 -07:00
|
|
|
<div *ngFor="let hero of heroes" mySpy class="heroes">
|
2016-01-20 19:14:46 -02:00
|
|
|
{{hero}}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<h4>-- Spy Lifecycle Hook Log --</h4>
|
2016-04-30 07:01:16 -07:00
|
|
|
<div *ngFor="let msg of spyLog">{{msg}}</div>
|
2016-01-20 19:14:46 -02:00
|
|
|
</div>
|
|
|
|
''',
|
|
|
|
styles: const [
|
|
|
|
'.parent {background: khaki; padding: 10px; margin:100px 8px}',
|
|
|
|
'.heroes {background: LightYellow; padding: 0 8px}'
|
|
|
|
],
|
|
|
|
directives: const [Spy],
|
|
|
|
providers: const [LoggerService])
|
|
|
|
class SpyParentComponent {
|
|
|
|
String newName = 'Herbie';
|
|
|
|
List<String> heroes = ['Windstorm', 'Magneta'];
|
|
|
|
List<String> spyLog;
|
|
|
|
LoggerService _logger;
|
|
|
|
|
|
|
|
SpyParentComponent(this._logger) {
|
|
|
|
spyLog = _logger.logs;
|
|
|
|
}
|
|
|
|
|
|
|
|
addHero() {
|
|
|
|
if (newName.trim().isNotEmpty) {
|
|
|
|
heroes.add(newName.trim());
|
|
|
|
newName = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
reset() {
|
|
|
|
_logger.log('-- reset --');
|
|
|
|
heroes.clear();
|
|
|
|
}
|
|
|
|
}
|