Angular 🇺🇦 - practical notes
Відкрити в Telegram
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!
Показати більше1 631
Підписники
Немає даних24 години
+17 днів
Немає даних30 днів
Архів дописів
✳️ 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
✳️ 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📄 Catch decorator in Angular
#angular #decorator #catch
✅ Article Link: https://javascript.plainenglish.io/a-try-catch-decorator-to-stylize-your-code-bdd0202765c8
🎁 Code Link: https://github.com/omirobarcelo/catch-decorator/blob/master/src/index.ts
📄 Debounce decorator in Angular
#angular #decorator #debounce
⚠️ Third-Party Lib
Usage example:
@Component({...})
export class ExampleComponent {
@Debounce(1000)
execute(arg: unknown) {
[ ... ]
}
}
✅ Article Link: https://blog.bitsrc.io/3-ways-to-debounce-http-requests-in-angular-c407eb165ada📄 View PDF in Angular
#angular #pdf #DomSanitizer
How to use?
Put the following code in HTML:
<embed [src]="sanitizedUrl | safeResourceUrl | async" class="pdf-content"/>✅ Article Link: https://itnext.io/you-dont-need-external-packages-to-view-pdf-in-angular-e47779f86595
📄
animationFrameScheduler example
#angular #rxjs #animationFrameScheduler
animationFrameScheduler is tailored for tasks that require synchronization with the browser's animation frame. It schedules tasks to be executed just before the next animation frame, ensuring smooth animations and minimizing unnecessary computations. For instance, we can utilize the animationFrameScheduler to update the UI based on animation frames, creating a visually pleasing and responsive user interface.
The scrollPosition$ observable captures the scroll position of the window on each scroll event. The animationFrameScheduler is used to ensure that the scroll position updates and smooth scrolling effect occur right before each animation frame, providing a visually smooth scrolling experience. When the user clicks the "scroll to top" button, the scrollPosition$ observable is subscribed to, and the window is scrolled smoothly towards the top in increments of 10 pixels until the scroll position reaches 0.
✅ Article Link: https://priyank-bhardwaj.medium.com/reactive-ninja-harnessing-rxjs-for-angular-mastery-part-2-7091aac29d60How to install Angular Server-Side Rendering (SSR) with NestJS
#angular #ssr #nestjs
✅ Article Link: https://medium.com/@pratheeshrussell/an-introduction-to-angular-server-side-rendering-ssr-with-nestjs-c121185d5824
🎁 Code Link: https://github.com/pratheeshrussell/angular-nest-ssr
📄 Implementing Edit-in-Place in Angular
#angular #directive #forms
✅ Article Link: https://netbasal.com/keeping-it-simple-implementing-edit-in-place-in-angular-4fd92c4dfc70
🎁 Code Link: https://stackblitz.com/edit/stackblitz-starters-1r4vtr?file=src%2Fapp%2Fapp.component.ts
🔄 React With Mediator Design Pattern
#react #mediator
Using the Mediator pattern as a state management solution in React applications also promotes modularization, making it easier to reuse components in other parts of the application or even in other applications.
✅ Article Link: https://itnext.io/improve-state-management-in-react-with-mediator-design-pattern-db632cbe6475
📄 Add missing functionality to third-party components using Directives
#angular #directive
When working with third-party components, there are times when you need to add missing functionality. We can create a directive that targets this input by
classname, and then we can use the Angular API to add what we need.
✅ Article link: https://netbasal.com/the-power-of-selectors-in-angular-cd6947ce3bfd📄 What’s new in CSS 2023
#css
⚠️ Experimental (not fully supported)
✅ Article link: https://medium.com/@trinhcamminh25112002/whats-new-in-css-and-ui-i-o-2023-edition-5bac2c7271bb
🎁 Code Link:
1.
@container: https://codepen.io/web-dot-dev/pen/KKxzYQx
2. new nth-child: https://codepen.io/web-dot-dev/pen/oNMRaQq
3. @scope: https://codepen.io/web-dot-dev/pen/MWPVGPL✳️ Handling custom errors in TS
#typescript #ts #angular #errors
Error handling in Type/JavaScript is a topic that doesn’t get the importance it deserves. It’s crucial to the longevity of any project to catch and log errors.
✅ Article Link: https://engineering.udacity.com/handling-errors-like-a-pro-in-typescript-d7a314ad4991
📄 How to use Cypress in 5 steps
#angular #cypress
Cypress is a desktop application. It supports multiple operating systems such as Windows, Linus, and iOS. Cypress is a tool that you can use to test a front-end application whatever the front-end framework you are using. E2E is a software testing method that simulates what the application should be able to do from the start to the end.
✅ Article Link: https://levelup.gitconnected.com/e2e-testing-with-cypress-angular-219eaa3926c
📄 Lesser-Known Tricks in HTML
#html
№1: Opening the Device Camera
<input type="file" capture="user" accept="image/*"> <input type="file" capture="environment" accept="video/*" />№2: Automatic Website Refresh
<head>
<meta http-equiv="refresh" content="10">
</head>
№3: Spellcheck Activation
<input type="text" spellcheck="true" lang="en">№4: Preventing Translation
<p translate="no">Brand name</p>№5: Automatic Download on Link Click
<a href="image.png" download>Download Image</a>№6 Responsive Images with srcset
<img srcset="image.jpg 1x, image@2x.jpg 2x, image@3x.jpg3x" src="image.jpg" alt="Responsive Image">
📄 Why Class/Component inheritance in your Angular app might not be good
#angular #inheritance
✅ Article Link: https://medium.com/hackernoon/why-class-component-inheritance-in-your-angular-app-might-not-be-good-a5d88fdd855b
📄 Angular 16 + Broadcast channel (Auth Fragments)
#angular #BroadcastChannel
✅ Article Link: https://techshareskk.medium.com/angular-16-broadcast-channel-4049a7f46019
📄 Angular Fallback Image
#angular #img #directive
✅ Article Link: https://medium.com/angular-man/angular-fallback-image-1f7fc3626e5f
📄 Angular Micro Frontend: Module Federation in 6 steps
#angular #ModuleFederation
Module Federation is a powerful feature provided by Webpack that enables the implementation of Micro Frontends in Angular. It allows you to dynamically load and integrate remote Angular modules (Micro Frontends) into a main application shell.
Module Federation handles the dynamic loading and sharing of modules, including their dependencies, at runtime. It enables applications to share code and resources, reducing duplication and improving the overall performance and development experience.
✅ Article Link: https://sagarsnath.medium.com/angular-micro-frontend-module-federation-5bc5638c963f
📄 @Attribute Decorator in Angular
#angular #decorator #attribute
As you can see, when we trigger the change detection by emitting the click event, Angular is checking the value.
We can be more efficient in this case if we use the @Attribute decorator. With this change, Angular will evaluate it once and forget about it. As a general rule, I prefer the @Attribute() approach when the string is a fixed value that never changes.
import { Component, Attribute } from '@angular/core';
@Component({...})
export class ButtonComponent {
constructor(
@Attribute('type')
public type: ButtonType = 'primary'
) {
}
}
✅ Article Link: https://netbasal.com/getting-to-know-the-attribute-decorator-in-angular-4f7c9fb61243⚠️ How to replace rxjs Subjects with Signals
#angular #rxjs #subject #signal
🚩> Angular 16
✅ Article Link: https://medium.com/ngconf/handling-user-actions-with-signals-in-angular-ff40bb63e857
🎁 Code Link: https://github.com/alfredoperez/ng-demos/blob/main/libs/demos/src/lib/demos/ngrx-with-signals/ngrx-with-signals.component.ts#LL53C15-L53C15
