What the Angular Formatter does
The Angular Formatter formats Angular component templates with Prettier 3.3.3, an open-source code formatter, running in your browser. It supports Angular template syntax such as *ngIf, bindings and pipes.
Angular Formatter examples
The built-in sample
Input
<ul *ngIf="items.length>0;else empty"><li *ngFor="let i of items;trackBy:byId" (click)="pick(i)" [class.on]="i.id===sel">{{i.name|uppercase}}</li></ul>Output
<ul *ngIf="items.length > 0; else empty">
<li
*ngFor="let i of items; trackBy: byId"
(click)="pick(i)"
[class.on]="i.id === sel"
>
{{ i.name | uppercase }}
</li>
</ul>
This is the input that the Load sample button fills in.
Event handlers, property bindings and control flow blocks
Input
<button (click)="save();close()" [disabled]="!form.valid||busy">{{'SAVE'|translate}}</button>
@if(a){<p>x</p>}Output
<button (click)="save(); close()" [disabled]="!form.valid || busy">
{{ "SAVE" | translate }}
</button>
@if (a) {
<p>x</p>
}
The two statements in the click handler are separated with a space, the binding expression gets spaces around ||, the pipe is spaced and its string becomes double-quoted. The @if block is indented like a JavaScript block.
Each output was produced by running this tool on the input above it.
How it works
The code is parsed with Prettier's angular parser and printed again from its syntax tree, using Prettier's default options: lines up to 80 characters and two-space indentation. The result therefore does not depend on how the input was laid out. If the code cannot be parsed, the parser's message with its line and column is shown instead of output.
Details and limits
- This formats template HTML. For a component's
.tsfile, use the TypeScript Formatter; a template written inside thetemplate:string of a component is not picked out of the TypeScript. - Expressions in
{{ }}, in property and event bindings and in structural directives are parsed and printed as Angular expressions. An expression that cannot be parsed is not reported as an error; it is left exactly as written. - The built-in control flow blocks
@if,@for,@switchand@deferare supported. - An element whose attributes do not fit on one line gets one attribute per line.
Questions
Is my data uploaded when I use Angular Formatter?
No. The tool runs in your browser, so what you paste or open is processed on your own device and is not sent to a server.
What does Angular Formatter do?
The Angular Formatter formats Angular component templates with Prettier 3.3.3, an open-source code formatter, running in your browser. It supports Angular template syntax such as *ngIf, bindings and pipes.
How does Angular Formatter work?
The code is parsed with Prettier's angular parser and printed again from its syntax tree, using Prettier's default options: lines up to 80 characters and two-space indentation. The result therefore does not depend on how the input was laid out.
Are there any limits I should know about?
This formats template HTML. For a component's.ts file, use the TypeScript Formatter; a template written inside the template: string of a component is not picked out of the TypeScript. Expressions in {{ }}, in property and event bindings and in structural directives are parsed and printed as Angular expressions. An expression that cannot be parsed is not reported as an error; it is left exactly as written.
Is there a size limit?
There is no fixed size limit. Everything happens on your device, so very large inputs depend on its memory and can take longer on a phone than on a computer.
Does it work on phones, and is it free?
Yes. It works in any current browser on Android phones, iPhones, tablets and computers. It is free and needs no account or sign-up.