2

I am trying to to this angular.equals(some_object, {}) inside an Ionic 2/3 application, but it cannot find the name angular. Basically I want to check is an object is empty using the built in angular equals method

Any ideas how to import it / access it?

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Patrioticcow
  • 26,422
  • 75
  • 217
  • 337

2 Answers2

0

There is no such method in angular. You can use loadash which will do the same job as angular.equals. See the below sample.

From the doc:

var object = { 'a': 1 };
var other = { 'a': 1 };

_.isEqual(object, other);
// => true

object === other;
// => false
Sampath
  • 63,341
  • 64
  • 307
  • 441
  • 1
    You are completely wrong. There's such method in Angular v1.x https://docs.angularjs.org/api/ng/function/angular.equals. – Fals Sep 20 '17 at 05:20
  • well, yeah, looks like angular 2 and whatnot doesn't have it. too bad. https://stackoverflow.com/questions/40597658/equivalent-of-angular-equals-in-angular2 – Patrioticcow Sep 20 '17 at 05:23
  • @Fals that documentation was for angular 1 not angular 2. – Atul Sharma Sep 20 '17 at 05:29
  • @atulquest93 read carefully, what is written. the methos exists where? Angular v1.x – Fals Sep 20 '17 at 05:30
  • op is asking for IONIC2 .. don't confuse him – Atul Sharma Sep 20 '17 at 05:31
  • @atulquest93 Say that something doesn't exist isn't the same as that exists in a previous version. Also, you can compare with pure TypeScript, there's no need to introduce another lib for this – Fals Sep 20 '17 at 05:33
  • 1
    @Fals ionic2/3 uses angular 2+ not angular v1 – Suraj Rao Sep 20 '17 at 05:41
  • When you're dealing with the multiple platforms it is recommended to use generic libraries rather than using vanilla javascript. Since those libraries have all the fixes for different browsers,versions and etc. @Fals – Sampath Sep 20 '17 at 06:28
  • Typescript is a super set of javascript. Your solution was ok, but why a lib when you already have this available in Typescript? Libs are cool, but they are not always the way to go. – Fals Sep 20 '17 at 14:28
  • May be you don't have any working experince with the cross platfrom mobile app developments.Plain `JS/TS` doesn't support all the browsers. But library does. That is why it recomended always. Another good exaple is `Momentjs`. @Fals – Sampath Sep 20 '17 at 14:56
0

Ionic2++ is based on new Angular framework, that has no such implementation. If you want to compare an object with an empty use Typescript, that has an abstraction for Object.is, same as ES6:

Object.is(object, {})

ES6: Object.is

Fals
  • 6,813
  • 4
  • 23
  • 43