I understand the Async pipe works on observable and help us load thing async for data which will be coming later.
However I can work without using async too. Following is the code
Component
export class XComponent{
someProp: string;
someList: string[];
someFn(){
this.someService.subscribe(
data=>{
this.someProp = data.prop;
this.someList = data.list;
}
);
}
}
Template
.....
<label>Prop</label>
<span>{{someProp}}</span>
<label>List</label>
<span *ngFor="let item of someList">{{item}}</span>
Above code works for me without use of async and without any issue. They why should I use async? Is it because we don't need to declare a variable for data and we can use directly observable (We anyways needs to declare a observable instead of data though)?
EDIT
Following is the code taken from angular docs for async example
@Component({
selector: 'async-observable-pipe',
template: '<div><code>observable|async</code>: Time: {{ time | async }}</div>'
})
export class AsyncObservablePipeComponent {
time = new Observable<string>((observer: Subscriber<string>) => {
setInterval(() => observer.next(new Date().toString()), 1000);
});
}
Instead of that I can write
@Component({
selector: 'async-observable-pipe',
template: '<div><code>observable|async</code>: Time: {{ time }}</div>'
})
export class AsyncObservablePipeComponent {
time;
constructor(){
setInterval(() => time = new Date().toString(), 1000);
}
}
To me second code looks clean too. (Even cleaner)