Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use rxjs isNumeric() function?

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?

like image 361
user8570495 Avatar asked Oct 02 '17 23:10

user8570495


1 Answers

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.

like image 196
John Montgomery Avatar answered Oct 03 '22 03:10

John Montgomery