Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the alternative of angular.isString() in angular2?

I am working on a project in angular2 and curious to know if there is any mean by which I can use angularjs functionalities in my angular2 application.

for ex.

in angularjs, I used to do following operations:

  1. angular.isString(value)
  2. angular.isArray(value)
  3. angular.copy(value)

I just want to know that is there any module or package which can help me do above operations in angular2/typescript?

Thanks in advance.

like image 927
Bhushan Gadekar Avatar asked Jun 08 '16 06:06

Bhushan Gadekar


2 Answers

Just use JavaScript:

  • isString

Simple

  typeof foo === 'string'
  • angular.isArray(value)

Simple

Array.isArray(value)
  • angular.copy(value)

Simple

Object.assign({},value)
like image 117
basarat Avatar answered Oct 13 '22 19:10

basarat


Except for copy, angular2 actually provides the isString and isArray (and a lot more) functions from "@angular/common/src/facade/lang". To use these you have to import them like this:

import {isString, isArray} from "@angular/common/src/facade/lang";

But, the body of these functions are the same as basarat mentioned, and this import is no longer available. Sooo, use the solution above :)

like image 28
Poul Kruijt Avatar answered Oct 13 '22 18:10

Poul Kruijt