Search code examples
ember.jsember-data

How to check two values are equal in ember handlebar without checking its type?


{{eq '1' 1}} -> matches type and returns false

Link:https://www.npmjs.com/package/ember-truth-helpers

eq if (a === b) {{if (eq a b)}}

In documentation it is checking for type tooo

I have also tried using is-equal helper it too returns false....


Solution

  • It’s rare that people want that kind of comparison, so you probably won’t find an addon that does it. But you could use a modified version of Ember Truth Helpers’s eq to use == instead of ===:

    import { helper } from '@ember/component/helper';
    
    export function equal(params) {
      return params[0] == params[1];
    }
    
    export default helper(equal);
    

    If you place such a file at app/helpers/double-eq you could use it with (double-eq 1 '1'). Probably there’s a clearer name than that, but you get the idea.