InterviewHubPRO
Section Overview
Q159

Question 159 of 283

Part 7: Change Detection, Security (XSS/Sanitizer) & Interceptors (151 - 176)

56%
Angular & Signals (283 Qs)•Part 7: Change Detection, Security (XSS/Sanitizer) & Interceptors (151 - 176)

What is rule in Schematics?

In schematics world, it's a function that operates on a file tree to create, delete, or modify files in a specific manner.

Practical Code Example

typescript
// Rule in Schematics: A function that takes a Tree, transforms files, and returns a new Tree:
import { Rule, Tree, SchematicContext } from '@angular-devkit/schematics';

export function myRule(): Rule {
  return (tree: Tree, context: SchematicContext) => {
    tree.create('hello.txt', 'world');
    return tree;
  };
}