Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an angular.noop for Angular 6?

Tags:

angular

noop

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?".

like image 282
Stack Underflow Avatar asked Oct 12 '18 15:10

Stack Underflow


People also ask

What is angular Noop?

A function that performs no operations. This function can be useful when writing code in the functional style. function foo(callback) { var result = calculateResult(); (callback || angular. noop)(result); }

What is Noop in RXJS?

https://rxjs.dev/api/index/function/noop. A function that does nothing. This is one of those things that you boggle at until you actually need it for something.


3 Answers

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

like image 63
SiddAjmera Avatar answered Oct 04 '22 20:10

SiddAjmera


This does nothing:

()=>{}

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

like image 22
Moika Turns Avatar answered Oct 04 '22 20:10

Moika Turns


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.

like image 23
Eli Avatar answered Oct 04 '22 21:10

Eli