Angular — Useful Code Snippets

Muhammad Faisal
2 min readJun 4, 2018

--

This article contains some useful Angular code snippets. Given below is a table of contents for this article:

  1. A Development Only Directive
  2. Executing Parallel API Requests
  3. Display * in Place of a Value

1. A Development Only Directive

You can use this directive on your component template elements to remove that specific code in the production build. This is helpful if you want to avoid commenting your code before production build and while the component is in active development.

Back to Top 🔝

2. Executing Parallel API Requests

Suppose we have an API endpoint for getting messages, and we want to get a list of messages by their IDs in parallel requests, we can use the following code for that:

Back to Top 🔝

3. Display * in Place of a Value

We can create a pipe e.g. password and apply that on a value where we want to display * or any other character instead of the actual value. The benefit of the pipe is that we'll be able to use it in our entire app and a change in single file will be reflected in all the places where the pipe is used.

StackBlitz Demo.

--

--