I'm new to rxjs but I think it's part of all ng apps and I've read that it has a handy isNumeric() function. I tried both of the following imports:
import 'rxjs/util/isNumeric';
import 'es6/util/isNumeric';
Here's some sample code that I tried to hook into this rxjs isNumeric() function:
var testString = "100";
//this doesn't compile
var isNumber = isNumeric(testString);
//this fails at runtime
var isNumber = testString.isNumeric();
What am I missing with this?
This isn't specifically a RxJS thing, but more generally how to import standalone functions from other files. There's (at least) two ways you can do this. Since isNumeric
only has one function, you can import it this way:
import {isNumeric} from "rxjs/util/isNumeric"
//
var isNumber = isNumeric(testString)
You can also import all the functions in a file at once like this:
import * as rxjsNumeric from "rxjs/util/isNumeric"
//
var isNumber = rxjsNumeric.isNumeric(testString)
But there's not much benefit to that in this particular case.
NOTE: As of RxJS 6, these utility functions are no longer available. However, the syntax still works for the general case of importing functions.
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