Im building service that should temporarily return Observable of some array before the server API will constructed. Before upgrading to angular and other packages to 6.0.0-rc.3 version i used following syntax:
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
@Injectable()
export class GeocodesService {
   getPositions():Observable<any>{     
        return Observable.of({ })
   }
}
At 6.0.0-rc.3, this syntax looks deprecated Trying to import it following way (using latest angular):
 import 'rxjs/observable/of'
But Getting error:
Module not found: Error: Can't resolve 'rxjs/observable/of'
How import of "of" can be done with latest rxjs?
Thanks
Finally found the solution here
This guy (Tomas Trajan), uses following syntax:
import { Observable , of} from 'rxjs'
and after you can use:
 getWidgets() {
    return of([]);
 }
If you want to use the patching imports with RxJS version 6, you will also need to install rxjs-compat.
It's a separate package that adds backwards compatibility (with RxJS version 5) to RxJS version 6:
npm install [email protected]
With rxjs-compat installed, your patching imports should work just fine.
For more information, see the migration guide.
You must change your imports and your instantiation. Check out Damien's blog post
Tl;dr:
import { Observable, fromEvent, of } from 'rxjs';
const yourResult = Observable
    .create(of(yourObservable))
    .startWith(null)
    .map(x => x.someStringProperty.toLowerCase());
//subscribe to keyup event on input element
Observable
    .create(fromEvent(yourInputElement, 'keyup'))
    .debounceTime(5000)
    .distinctUntilChanged()
    .subscribe((event) => {
        yourEventHandler(event);
    });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With