Angular πŸ‡ΊπŸ‡¦ - practical notes
1.63K subscribers
1.6K photos
1 file
532 links
Angular - practical notes

This group is for posting practical notes for Angular developers. Mostly all posts are for quick implementation https://t.me/angular_practical_notes (Commenting on posts only in ENG and UA langs here). Welcome!
Download Telegram
✳️ Handle subscriptions directly from template with Init Directive

#angular #directive

The problem is every async pipe usage creates a new subscription which is not what you really want to see in your project. Moreover this approach won’t work if your’re dealing with cold observables such as http requests. Because in that case every subscriber will get different value. You might know about as keyword in`ngIf ` to bind a template property of some data and solve the problem of reusing same data multiple times. But what if we don’t want to hide this piece of template in any condition. Or imagine we have a lot of streams, which we need to reuse. That would be a bunch of pointless ngIf directives!

βœ… Article Link: https://medium.com/@mikekucherov92/angular-utilities-init-directive-8dc4e0a4723c

🎁 Code Link:
https://gist.github.com/mikekucherov/9677d444148e7f1f8890e0130402b1de#file-init-params-component-html
https://gist.github.com/mikekucherov/84caf26cb387eb904877552531151d1a#file-init-directive-ts
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘2
This media is not supported in your browser
VIEW IN TELEGRAM
✳️ Implementing a Loading Skeleton in Angular

#angular #directive #skeleton #ui_element

Skeletons are placeholder elements that are displayed before the actual content is loaded on a webpage. A skeleton is usually a light gray box or circle that you see on websites like Medium, YouTube, etc. Skeletons convey a visual impression of the feature, which gives them an advantage over spinners.

βœ… Article Link: https://netbasal.com/implementing-a-loading-skeleton-in-angular-7490ffdecc1b

🎁 Code Link:
Step 1: https://gist.github.com/NetanelBasal/33f8ec9a106ee2367f3b9847fd3043cb#file-rect-ske-component-ts

Step 2: https://gist.github.com/NetanelBasal/82030b63d6ed0055c09a543483bd3470#file-skeleton-directive-ts

Step 3: https://gist.github.com/NetanelBasal/0f26e85d13d10a9e564541553094c12f#file-skeleton-demo-html
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
❀2
πŸ“„ Theming for Angular Applications with CSS Variables

#angular #guide #theming

1. Install required packages
Install the font-awesome/angular-fontawesome package for creating the theme switcher later.

npm install --save @font-awesome/angular-fontwaesome

2. Define CSS variables
First, we have to define colors as CSS variables in the styles.scss. The properties defined in the :root section could be referred to globally.

:root represents the <html> element and is identical to the selector html .

🎁 Code Link

3. Create pre-defined themes
Create a new TypeScript file.

β€” Define required theme types (line 1 ~ line 4)
β€” Define required themes in the JSON format (line11 ~ line 35)


🎁 Code Link

4. Create a theme service to operate the theme
Create a new service from the ng-cli.
ng g s theme

Update the service.

β€” Expose the method to retrieve the theme type from memory and localStorage (line 20 ~ line 23)
β€” Expose the method to set the theme type to memory and localStorage (line 42 ~ line 47)

The key is document.documentElement(line 55). It stands for the root DOM. In setCurrentTheme() , we set the new value for the corresponding theme.


🎁 Code Link

5. Create a theme component for the theme switcher

Create a new component from the ng-cli.
ng g c theme

Update the theme.component.ts.

β€” In ngOnInit() phase, we set the corresponding icon for the theme type retrieved from the service (line 23 ~ line 26)
β€” When the user toggles, we set the icon for the next theme type retrieved from the service (line 28 ~ line 32)


🎁 Code Link

Update the theme.component.html to place the icon.


🎁 Code Link

Update the theme.component.scss to switch the theme of the icon.


🎁 Code Link

The theme switcher will look like the following images.


βœ… Article link
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘4