I am very new to Angular and Typescript. I wonder how exactly this import syntax works?
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';
I know that Typescript syntax is "import X from Y", however, we have only "import X" here?
I found in typescript documentation this:
"Import a module for side-effects only Though not recommended the practice, some modules set up some global state that can be used by other modules. These modules may not have any exports or the consumer is not interested in any of their exports."
But this is not clear to me. What exactly do we import with the examples above?Which are the side effects? Are "of" and "do" functions?
(My question is about the general typescript import syntax, not a question 'how to' import some specific Rxjs operator)
Thanks
In this case, importing these files will patch the rxjs Observable prototype. But you can think about any side-effect. The easiest side-effect can be log in the console.
File side-effect.ts
console.log('I am side effect!');
Your main typescript file
import './side-effect.ts';
Now, if you run the code in your main file, it will log "I am side effect!" in the console, because of the side effect of the import.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments