Angular - Services and Dependency Injection
Given this service and component code, what will be logged?
export class CounterService {
count = 0;
increment() { this.count++; }
}
@Component({ selector: 'app-one', template: '' })
export class OneComponent {
constructor(private counter: CounterService) {}
ngOnInit() { this.counter.increment(); console.log(this.counter.count); }
}
@Component({ selector: 'app-two', template: '' })
export class TwoComponent {
constructor(private counter: CounterService) {}
ngOnInit() { this.counter.increment(); console.log(this.counter.count); }
}