Peter Parker Peter Parker - 1 month ago 8
TypeScript Question

angular.isUndefined & angular.equals in angular 2

I just began to try to migrate from angular 1 to 2, actually from ionic 1 to 2, and one of my first compilation error is that angular.isUndefined and angular.equals aren't resolved.

How should I fix that, any tips?

namespace Utils {

export class Comparator {

static isEmpty(obj:any):boolean {
return obj == null || Object.keys(obj).length === 0;
}

static isNumberNullOrZero(obj:number):boolean {
return obj == null || obj === 0;
}

static equals(obj1:any, obj2:any):boolean {
return angular.equals(obj1, obj2); // <== here angular unresolved
}

static isStringEmpty(str:string):boolean {
return !str || 0 === str.length;
}

static isStringBlank(str:string):boolean {
return !str || /^\s*$/.test(str);
}

static isBiggerThanZero(num:number):boolean {
return num != null && !angular.isUndefined(num) && num > 0; // <== here angular unresolved
}

}
}

Answer

In your case you can simply replace angular.isUndefined(num) with num === undefined.

Object equality is a bit trickier. There are libraries that include such functionality, e.g. Lodash

Comments