timer (0, 1000) // timer, a value of each emitting 1000ms, the delay time of the initial transmission values 0s;
.pipe (
Take (. 5), // take the first 5 values
takeWhile (value => value> -1 ) // long as one is not greater than 1; i.e. Complete execution; end Next
Materialize () // specific, each value is converted to a Notification object
)
.subscribe ({
Next (value) {
the console.log (value );
}
});
results are as follows:
--------------------------------------------------------------------------------------------------------------
materialize
It is toObservable弹射
convert the data into an eventNotification
object / subject;dematerialize
It isNotification物件/对象
converted toObservable
the event information.
-------------------------------------------------------------------------
timer (0, 1000) // timer, a value of each emitting 1000ms, the delay time of the initial transmission values 0s;
.pipe (
Take (. 5), // take the first 5 values
takeWhile (value => value> -1 ) // long as one is not greater than 1; i.e. Complete execution; end Next
materialize () // specific, each value is converted to a Notification objects
dematerialize (), with the opposite // materialize operation; Notification objects into the Object of Observable
)
.subscribe ({
Next (value) {
the console.log (value);
}
});
Results are as follows:
of(1, 2, 3, 'a', 4)
.pipe(
materialize(),
map(x => x.kind === NotificationKind.COMPLETE ? x : new Notification(x.kind, x.value + ' hello'))
)
.subscribe(value => {
console.log(value);
});
Through the above example, we know a Notification
least contains several information
kind
: Current status information: N (Next), E (Error), C (Complete)value
: Value / datahasValue
: Is there include dataerror
: Error message
Also can be used as new Notification()
the way of the establishment.