9

In my Angular 6 application, I need a function that does nothing. Obviously, I could just write my own, but I was reading about angular.noop which I would like to use. However, I get an angular.noop is not a function error when I try to use it. I could not find anything about this in Angular's documentation. Is there an Angular 6 version of AngularJS's angular.noop function?

I know what noop is. This is not a duplicate of What is Angular.noop used for?. I am asking about Angular 6. My question is very simply "Is there a noop function built into Angular 6 like there is in AngularJS?".

Stack Underflow
  • 2,023
  • 1
  • 24
  • 41

4 Answers4

19

You could use noop which is a helper function from Rxjs for this:

import { noop } from 'rxjs';
...
// this does nothing.
noop(); 

I don't really think Angular has noop

SiddAjmera
  • 35,416
  • 5
  • 56
  • 100
4

This does nothing:

()=>{}

It's no more characters than noop() and doesn't need an import.

Moika Turns
  • 577
  • 8
  • 16
3

No. There is not a noop function in Angular 6.

Stack Underflow
  • 2,023
  • 1
  • 24
  • 41
3

I'm assuming you want to use this with (click). Try:

(click)="!!false"

it works and the compiler doesn't complain. Maybe there is a more semantic solution.

Eli
  • 1,302
  • 1
  • 17
  • 21