ch
Feedback

不要被骗子欺骗!Telemetrio 会找到并标记这些频道 👉 如果想查看标记,请订阅

Angular 🇺🇦 - practical notes

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 天
帖子存档
📄 Theming for Angular Applications with CSS Variables #angular #guide #theming 1. Install required packages Install the font
📄 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

🤓 Different Types of Errors in JavaScript and How to Handle Them #js #errors ✅ Article link
+5
🤓 Different Types of Errors in JavaScript and How to Handle Them #js #errors ✅ Article link

📄 Angular Declarative Control Flow & Deferrable Views #angular #controlFlow #defer 🚩 > Angular 17 ✅ Article link
+8
📄 Angular Declarative Control Flow & Deferrable Views #angular #controlFlow #defer 🚩 > Angular 17 ✅ Article link

🤓 JS Techniques for Developers #js ✅ Article link
+5
🤓 JS Techniques for Developers #js ✅ Article link

📄 1/2 One-Liners Every Dev Needs to Know #css 1. Prevent Text Selection
.no-select { user-select: none }
2. Responsive Text Size
Enter the magic of clamp(): this CSS function dynamically adjusts the font size based on the viewport width, ensuring your text is always just right.
.responsive-text { font-size: clamp(1rem, 2.5vw, 2rem) }
3. Maintain Aspect Ratio
Perfect for responsive design, setting an element’s aspect ratio will scale it beautifully while keeping its width and height in a specified ratio.
.aspect-ratio { aspect-ratio: 16 / 9 }
4. Automatic Smooth Scrolling
Simply applying scroll-behavior: smooth to the <html> element makes any anchor link or navigation jumps glide gently instead of the default abrupt jump
html { scroll-behavior: smooth }
5. Scroll Snapping
This forces scrollable content to lock to a certain element, making it perfect for image galleries or a horizontally scrolling menu
.scroll-snap { scroll-snap-type: x mandatory }
6. Responsive Dark Mode
Automatically switch your website’s theme to dark mode based on the user’s system preferences with this CSS media query (the one-liner here is the media query).
@media (prefers-color-scheme: dark) {
  body {
    background-color: #333;
    color: #fff;
  }
}
7. Full-width Responsive Images
This piece of CSS makes images fully adaptable to various screen sizes.
.cover-img { object-fit: cover }
8. Disable Pointer Interactions
Use this to make an element ignore pointer events like mouse clicks, which is particularly useful for overlays or disabled buttons.
.cover-img { object-fit: cover }
9. Blurry Background or Elements
This CSS declaration adds a blur effect to any element, great for creating focus on modal windows or for artistic background effects.
.blur { filter: blur(20px) }
10. Dynamic Content from HTML Attributes
Dynamically insert content before (or after) an element based on its class name.
.dynamic-content::before { content: attr(class) }
✅ Article link

📄Managing the Sticky Navigation: Angular, Tailwind, and RxJS #angular #rxjs #tailwind #navbar #ui_element Explanation: — `pu
+1
📄Managing the Sticky Navigation: Angular, Tailwind, and RxJS #angular #rxjs #tailwind #navbar #ui_element
Explanation: — `public readonly isSticky$ = fromEvent(window, 'scroll').pipe(...):` This defines the isSticky$ observable using RxJS operators. It listens for scroll events on the window, maps them to the vertical scroll position (window.scrollY), filters out consecutive duplicate values, and then maps the scroll position to a boolean value indicating whether the scroll position is greater than 24 (assuming 24 is a threshold value for determining when the navigation bar should become sticky). — `distinctUntilChanged()`: This operator filters out consecutive duplicate values emitted by the observable. — `map((scrollTop: number) => scrollTop > 24)`: This operator maps the scroll position (scrollTop) to a boolean value, indicating whether the user has scrolled past a certain threshold (24 in this case). — `(isSticky$ | async) === true`: This condition checks if the value emitted by the isSticky$ is true or not. Which makes it convenient since you don’t have to unsubscribe the observable. — `sticky top-0 z-10 shadow-lg opacity-95 bg-white`: These classes from TailWind will help enhance the sticky experience when the users scroll down.
✅ Article link

📄 Angular HostAttributeToken: the new way to inject attributes #angular #attribute #HostAttributeToken By creating an input,
+1
📄 Angular HostAttributeToken: the new way to inject attributes #angular #attribute #HostAttributeToken
By creating an input, you are instructing Angular to create a binding to that property and check it during each change detection cycle. That is really excessive, you only need that property to be checked once during component initialization. 🤯 To make this more performant you can instead inject the host-element attribute in the constructor thanks to the Attribute decorator
Since the release of Angular 14 there is now a cleaner approach to inject providers without using the constructor class: the inject() function. Up until now, this inject() function allowed to inject easily components, directives and pipes, but it was missing a method to inject host attributes. And that’s precisely why the HostAttributeToken class was introduced
✅ Article link

📄 Browser Fetch Priority API #js #fetch #fetchpriority At the time of writing this article, the fetchpriority attributed is
+1
📄 Browser Fetch Priority API #js #fetch #fetchpriority
At the time of writing this article, the fetchpriority attributed is supported on the following elements: — img — script — link — iframe The fetchpriority attribute can take on one of three values: — high: Designates the resource as high priority, requesting the browser to prioritize it unless its heuristics advise otherwise. — low: Marks the resource as low priority, instructing the browser to deprioritize it if its heuristics allow. — auto: The default value, indicating no specific preference, allowing the browser to autonomously determine the suitable priority.
✅ Article link

📄 СSS becomes SCSS #css #scss #root #nesting #is #has #container @layer Sass has established itself as a powerful preprocess
+4
📄 СSS becomes SCSS #css #scss #root #nesting #is #has #container @layer
Sass has established itself as a powerful preprocessor installed locally, forming the backbone of my projects for over a decade. It enabled me to efficiently organize scalable and stable CSS packages. Even today, I still consider Sass to be an extraordinarily powerful tool. Yet, as we step into the year 2024, it’s undeniable that CSS has undergone rapid development. Features that were once unique to Sass are now natively integrated into CSS, including variables and the latest highlight: CSS Nesting.
✅ Article link

📄 Detect autofill events in Angular #angular #directive ✅ Article link
+1
📄 Detect autofill events in Angular #angular #directive ✅ Article link

📄 8/8 JS Reactive Patterns: Reactive Scrolling With IntersectionObserver #js #patterns #IntersectionObserver The Intersectio
📄 8/8 JS Reactive Patterns: Reactive Scrolling With IntersectionObserver #js #patterns #IntersectionObserver
The IntersectionObserver API enables reacting to the intersection of a target element with another element or the viewport area.

I would like to get to know my subscribers a little, who is from what country? (Or your option in comments)
Anonymous voting

📄 7/8 JS Reactive Patterns: Custom Events as a Browser Version Of PubSub #js #patterns #CustomEvent The browser offers an AP
📄 7/8 JS Reactive Patterns: Custom Events as a Browser Version Of PubSub #js #patterns #CustomEvent
The browser offers an API for triggering and subscribing to custom events through the CustomEvent class and the dispatchEvent method. The latter provides us with the ability not only to trigger an event but also to attach any desired data to it.

📄 6/8 JS Reactive Patterns: Reactive HTML Attributes With MutationObserver #js #patterns #MutationObserver One way to achiev
📄 6/8 JS Reactive Patterns: Reactive HTML Attributes With MutationObserver #js #patterns #MutationObserver
One way to achieve reactivity in the DOM is by using MutationObserver. Its API allows us to observe changes in attributes and also in the text content of the target element and its children.

📄 5/8 JS Reactive Patterns: Individual Object Properties and Reactivity #js #patterns #defineProperty If you don’t need to t
📄 5/8 JS Reactive Patterns: Individual Object Properties and Reactivity #js #patterns #defineProperty
If you don’t need to track all the fields in the objects, you can choose the specific one using Object.defineProperty or group of them with Object.defineProperties.

📄 4/8 JS Reactive Patterns: Reactive Properties With Proxy #js #patterns #proxy If you want to react to changes in objects,
📄 4/8 JS Reactive Patterns: Reactive Properties With Proxy #js #patterns #proxy
If you want to react to changes in objects, Proxy is the way to go. It lets us achieve reactivity when setting or getting values of object fields.

📄 3/8 JS Reactive Patterns: Observer #js #patterns #observer The Observer pattern is really similar to PubSub. You subscribe
📄 3/8 JS Reactive Patterns: Observer #js #patterns #observer
The Observer pattern is really similar to PubSub. You subscribe to the Subject and then it notifies its subscribers (Observers) about changes, allowing them to react accordingly. This pattern plays a significant role in building decoupled and flexible architecture.

📄 2/8 JS Reactive Patterns: Custom Event Targets #js #patterns #customEvent If you prefer not to dispatch events globally on
📄 2/8 JS Reactive Patterns: Custom Event Targets #js #patterns #customEvent
If you prefer not to dispatch events globally on the window object, you can create your own event target. By extending the native EventTarget class, you can dispatch events to a new instance of it. This ensures that your events are triggered only on the new class itself, avoiding global propagation. Moreover, you have the flexibility to attach handlers directly to this specific instance.

📄 1/8 JS Reactive Patterns: PubSub or Publish-Subscribe #js #patterns #pubsub PubSub is one of the most commonly used and fu
📄 1/8 JS Reactive Patterns: PubSub or Publish-Subscribe #js #patterns #pubsub
PubSub is one of the most commonly used and fundamental reactivity patterns. The Publisher is responsible for notifying Subscribers about the updates and the Subscriber receives those updates and can react in response. One popular example of its usage is Redux. This popular state management library is based on this pattern (or more specifically, the Flux architecture). Things work pretty simple in the context of Redux: — Publisher: The store acts as the publisher. When an action is dispatched, the store notifies all the subscribed components about the state change. — Subscriber: UI Components in the application are the subscribers. They subscribe to the Redux store and receive updates whenever the state changes.