Skip to main content

Navigating WCAG 2.1: A Step-by-Step Approach for Developers

 Get Familiar with WCAG 2.1: WCAG 2.1 is like the rulebook for web accessibility. It's split into four parts: Perceivable, Operable, Understandable, and Robust (POUR). For instance, "Perceivable" includes rules like giving all images a text description (alt text) for folks who can't see them.  Run an Accessibility Audit: Use tools like Google Lighthouse or WAVE to scan your site. They'll flag up stuff like missing alt text, low color contrast, or form fields without labels.  Manual Testing: Automated tools can't catch everything. You'll need up roll to your sleeves and do some manual testing. Try navigating your site using only your keyboard, or using a screen reader like NVDA or VoiceOver. You're checking that all content and functionality is accessible.   Write an Accessibility Statement: This is a page on your site where you talk about your commitment to accessibility. You could mention that you're aiming for WCAG 2.1 Level AA compliance, lis...

Error Handling with HttpClient and HttpInterceptor in Angular

To handle your errors properly in angular, you can use HttpInterceptor. It intercepts Http request. It helps in converting http request before sending and after getting the response from the server.



import {
    HttpEvent,
    HttpHandler,
    HttpRequest,
    HttpErrorResponse,
    HttpInterceptor
} from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
import { catchError, retry } from 'rxjs/operators';

export class MyErrorInterceptor implements HttpInterceptor {
    intercept(
        request: HttpRequest,
        next: HttpHandler
    ): Observable> {
        return next.handle(request)
            .pipe(
                retry(1),
                catchError((error: HttpErrorResponse) => {
                    let errorMessage = '';
                    if (error.error instanceof ErrorEvent) {
                        // client-side error
                        errorMessage = `Error: ${error.error.message}`;
                    } else {
                        // server-side error
                        errorMessage = `Error Status: ${error.status}\nMessage: ${error.message}`;
                    }
                    console.log(errorMessage);
                    return throwError(errorMessage);
                })
            )
    }
}

After this you can inlude your ErrorIntercept in your app module like shown below. When you use integrate service within any of your component every http request you made gets intercept by ErrorIntercept. It will validates all your http request.

import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { MyErrorInterceptor } from './error.interceptor';

@NgModule({
  declarations: [...],
  imports: [
    HttpClientModule
  ],
  providers: [
    {
      provide: HTTP_INTERCEPTORS,
      useClass: MyErrorInterceptor,
      multi: true
    }
  ],
  bootstrap: [...]
})

export class AppModule { }
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';

class User {
    constructor(
        public id: string,
        public name: string,
        public email: string
    ) { }
}

@Injectable({
    providedIn: 'root'
})

export class MyService {
    private url = '/api';

    constructor(private http: HttpClient) { }

    getUsers(): Observable {
        return this.http.get(url)
    }
}

Comments

Popular posts from this blog

Flexbox CSS Cheat Sheet by Learnpine

 

Navigating WCAG 2.1: A Step-by-Step Approach for Developers

 Get Familiar with WCAG 2.1: WCAG 2.1 is like the rulebook for web accessibility. It's split into four parts: Perceivable, Operable, Understandable, and Robust (POUR). For instance, "Perceivable" includes rules like giving all images a text description (alt text) for folks who can't see them.  Run an Accessibility Audit: Use tools like Google Lighthouse or WAVE to scan your site. They'll flag up stuff like missing alt text, low color contrast, or form fields without labels.  Manual Testing: Automated tools can't catch everything. You'll need up roll to your sleeves and do some manual testing. Try navigating your site using only your keyboard, or using a screen reader like NVDA or VoiceOver. You're checking that all content and functionality is accessible.   Write an Accessibility Statement: This is a page on your site where you talk about your commitment to accessibility. You could mention that you're aiming for WCAG 2.1 Level AA compliance, lis...

Few Must-Have Web Dev Tools for front-end developers

Keyframes A couple of very user-friendly and simple visual tools to help you generate CSS (animations, shadows, colors) for your projects. Clippy Clippy is another amazing tool that you can use for image clipping. CSS Stats Very useful to get CSS Stats of the webpage. It provides a report with deep analytics and visualizations for your stylesheets. CSS Hell Common mistakes developers make Color Leap Website to get good combinations of color pallets based on paintings. HTML DOM A handy DOM-related knowledge database for developers Animista The best site for getting animation keyframes. It contains lots of cool examples with code. Blush Easily create stunning and beautiful illustrations with collections made by artists across the globe. .