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:
- angular.isString(value)
- angular.isArray(value)
- 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.
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:
- angular.isString(value)
- angular.isArray(value)
- 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.
Share Improve this question asked Jun 8, 2016 at 6:43 Bhushan GadekarBhushan Gadekar 13.8k21 gold badges88 silver badges131 bronze badges3 Answers
Reset to default 15Just use JavaScript:
- isString
Simple
typeof foo === 'string'
- angular.isArray(value)
Simple
Array.isArray(value)
- angular.copy(value)
Simple
Object.assign({},value)
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 :)
You could use lodash-es (ES module import support for lodash) to do the following:
import { isString } from 'lodash-es';
console.log(isString('') === true);
I prefer this over the accepted answer of typeof foo === 'string'
because string literals are prone to mistakes and are harder to minify.