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,363
  • 2
  • 26
  • 51

4 Answers4

20

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
  • 38,129
  • 5
  • 72
  • 110
4

This does nothing:

()=>{}

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

Moika Turns
  • 677
  • 11
  • 17
3

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

Stack Underflow
  • 2,363
  • 2
  • 26
  • 51
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,670
  • 1
  • 20
  • 23