From the comments on my other answer (preserved since it may be helpful to someone), you seem to want to leverage the power of something to emit values over time.
As DOMZE proposed, use a Subject, but here's a (trivial) example showing how you could do that. Though there are evidently some pitfalls to avoid in using Subject directly, I'll leave that up to you.
import { Component, NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { Observable, Subject } from 'rxjs/Rx';
@Component({
selector: 'my-app',
template: `
<div>
<h2>Open the console.</h2>
</div>
`,
})
export class App {
constructor() {}
let subject = new Subject();
// Subscribe in Component
subject.subscribe(next => {
console.log(next);
});
setInterval(() => {
// Make your auth call and export this from Service
subject.next(new Date())
}, 1000)
}
@NgModule({
imports: [ BrowserModule ],
declarations: [ App ],
bootstrap: [ App ]
})
export class AppModule {}
Plunker
In my humble opinion, for this scenario, I don't see why a simple Service/Observable doesn't suffice, but that's none of my business.
Further reading: Angular 2 - Behavior Subject vs Observable?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…