Search code examples
angularlodash

Angular use lodash in HTML template


Please, could someone tell me how to use Lodash in an Angular HTML template file?

I know how to use it in a component's TypeScript file but not in the component's HTML file.

Thanks

PS This is NOT a dupe of AngularJs: Have Underscore/Lodash/_ in the view template because that relates to AngularJS not Angular.


Solution

  • If you import the module in your TS file, you can assign it to a property of the class and use it in your HTML without any problem.

    import * as _ from 'lodash';
    ...
    export class YourClass {
      lodash = _;
      ...
    }
    

    <p> {{lodash.isEqual(1,1)}} </p>