0
0
Angularframework~10 mins

Standalone pipes and directives in Angular - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a standalone pipe in Angular.

Angular
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'exclaim',
  standalone: [1]
})
export class ExclaimPipe implements PipeTransform {
  transform(value: string): string {
    return value + '!';
  }
}
Drag options to blanks, or click blank then click option'
Atrue
Bnull
C'yes'
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Setting standalone to false or omitting it.
2fill in blank
medium

Complete the code to declare a standalone directive in Angular.

Angular
import { Directive, ElementRef, Renderer2 } from '@angular/core';

@Directive({
  selector: '[highlight]',
  standalone: [1]
})
export class HighlightDirective {
  constructor(private el: ElementRef, private renderer: Renderer2) {
    this.renderer.setStyle(this.el.nativeElement, 'backgroundColor', 'yellow');
  }
}
Drag options to blanks, or click blank then click option'
Afalse
Btrue
Cundefined
D'true'
Attempts:
3 left
💡 Hint
Common Mistakes
Using string 'true' instead of boolean true.
3fill in blank
hard

Fix the error in the standalone pipe declaration by completing the missing property.

Angular
import { Pipe, PipeTransform } from '@angular/core';
import { CommonModule } from '@angular/common';

@Pipe({
  name: 'reverse',
  standalone: true,
  [1]: [CommonModule]
})
export class ReversePipe implements PipeTransform {
  transform(value: string): string {
    return value.split('').reverse().join('');
  }
}
Drag options to blanks, or click blank then click option'
Adeclarations
Bproviders
Cimports
Dexports
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'providers' or 'declarations' which are not valid here.
4fill in blank
hard

Fill both blanks to create a standalone directive that imports CommonModule and exports itself.

Angular
import { Directive } from '@angular/core';
import { CommonModule } from '@angular/common';

@Directive({
  selector: '[blink]',
  standalone: true,
  [1]: [CommonModule],
  [2]: [BlinkDirective]
})
export class BlinkDirective {}
Drag options to blanks, or click blank then click option'
Aimports
Bexports
Cproviders
Ddeclarations
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing 'providers' or 'declarations' with 'imports' or 'exports'.
5fill in blank
hard

Fill all three blanks to create a standalone pipe that imports CommonModule, exports itself, and has a pure transform method.

Angular
import { Pipe, PipeTransform } from '@angular/core';
import { CommonModule } from '@angular/common';

@Pipe({
  name: 'capitalize',
  standalone: true,
  [1]: [CommonModule],
  [2]: [CapitalizePipe],
  pure: [3]
})
export class CapitalizePipe implements PipeTransform {
  transform(value: string): string {
    return value.charAt(0).toUpperCase() + value.slice(1);
  }
}
Drag options to blanks, or click blank then click option'
Aimports
Bexports
Ctrue
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Setting pure to false or omitting imports/exports.