|
| 1 | +--- |
| 2 | +authors: "fisker" |
| 3 | +title: "Prettier 3.8: Support for Angular v21.1" |
| 4 | +--- |
| 5 | + |
| 6 | +We're excited to announce that Prettier now fully supports the fresh features landing in Angular v21.1 (released today 🎉)! |
| 7 | + |
| 8 | +This update brings cleaner, more expressive templates with: |
| 9 | + |
| 10 | +- Consecutive `@case` statements in `@switch` blocks. |
| 11 | +- Spread elements (`...`) in array literals, object literals, and function calls inside templates. |
| 12 | + |
| 13 | +We've also added the ability to format Angular syntax beautifully inside Markdown code blocks. |
| 14 | + |
| 15 | +If you find Prettier valuable and want to help us keep pace with fast-moving frameworks like Angular, please consider [sponsoring us on OpenCollective](https://opencollective.com/prettier) or supporting the projects we rely on. Thank you for being part of this community — your support means a lot! |
| 16 | + |
| 17 | +<!-- truncate --> |
| 18 | + |
| 19 | +## Highlights |
| 20 | + |
| 21 | +### Angular |
| 22 | + |
| 23 | +#### Support for consecutive switch cases ([#18593](https://github.com/prettier/prettier/pull/18593) by [@fisker](https://github.com/fisker)) {#change-18593} |
| 24 | + |
| 25 | +<!-- prettier-ignore --> |
| 26 | +```html |
| 27 | +<!-- Input --> |
| 28 | +@switch (userRole) { |
| 29 | + @case ('admin') |
| 30 | + @case ('moderator') { |
| 31 | + <p>Welcome, boss! Full access.</p> |
| 32 | + } |
| 33 | + @case ('user') { <p>Standard access</p> } |
| 34 | + @default { <p>Guest view</p> } |
| 35 | +} |
| 36 | + |
| 37 | +<!-- Prettier 3.7 --> |
| 38 | +SyntaxError: Incomplete block "case". If you meant to write the @ character, you should use the "@" HTML entity instead. (2:3) |
| 39 | + |
| 40 | +<!-- Prettier 3.8 --> |
| 41 | +@switch (userRole) { |
| 42 | + @case ("admin") |
| 43 | + @case ("moderator") { |
| 44 | + <p>Welcome, boss! Full access.</p> |
| 45 | + } |
| 46 | + @case ("user") { |
| 47 | + <p>Standard access</p> |
| 48 | + } |
| 49 | + @default { |
| 50 | + <p>Guest view</p> |
| 51 | + } |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +#### Support for spread elements ([#18596](https://github.com/prettier/prettier/pull/18596), [#18636](https://github.com/prettier/prettier/pull/18636) by [@prettier](https://github.com/prettier)) {#change-18596} |
| 56 | + |
| 57 | +<!-- prettier-ignore --> |
| 58 | +```html |
| 59 | +<!-- Input --> |
| 60 | +<MyComponent |
| 61 | + [array]="[ ...foo, ...bar]" |
| 62 | + [object]="{...bar, ...extra }" |
| 63 | + [call]="call( ...baz)" |
| 64 | +/> |
| 65 | + |
| 66 | +<!-- Prettier 3.7 --> |
| 67 | +<MyComponent |
| 68 | + [array]="[ ...foo, ...bar]" |
| 69 | + [object]="{...bar, ...extra }" |
| 70 | + [call]="call( ...baz)" |
| 71 | +/> |
| 72 | + |
| 73 | +<!-- Prettier 3.8 --> |
| 74 | +<MyComponent |
| 75 | + [array]="[...foo, ...bar]" |
| 76 | + [object]="{ ...bar, ...extra }" |
| 77 | + [call]="call(...baz)" |
| 78 | +/> |
| 79 | +``` |
| 80 | + |
| 81 | +## Other Changes |
| 82 | + |
| 83 | +### Angular |
| 84 | + |
| 85 | +#### Don't print attribute values that are single template or string literals on new lines ([#18378](https://github.com/prettier/prettier/pull/18378) by [@ravindUwU](https://github.com/ravindUwU)) {#change-18378} |
| 86 | + |
| 87 | +<!-- prettier-ignore --> |
| 88 | +```html |
| 89 | +<!-- Input --> |
| 90 | +<component |
| 91 | + [property]="` |
| 92 | + template |
| 93 | + literal |
| 94 | + `" |
| 95 | +/> |
| 96 | + |
| 97 | +<!-- Prettier 3.7 --> |
| 98 | +<component |
| 99 | + [property]=" |
| 100 | + ` |
| 101 | + template |
| 102 | + literal |
| 103 | + ` |
| 104 | + " |
| 105 | +/> |
| 106 | + |
| 107 | +<!-- Prettier 3.8 --> |
| 108 | +<component |
| 109 | + [property]="` |
| 110 | + template |
| 111 | + literal |
| 112 | + `" |
| 113 | +/> |
| 114 | +``` |
| 115 | + |
| 116 | +### Markdown |
| 117 | + |
| 118 | +#### Support formatting Angular syntax in code block ([#18519](https://github.com/prettier/prettier/pull/18519) by [@fisker](https://github.com/fisker)) {#change-18519} |
| 119 | + |
| 120 | +<!-- prettier-ignore --> |
| 121 | +````md |
| 122 | +<!-- Input --> |
| 123 | +```angular-ts |
| 124 | +@Component({ |
| 125 | + selector: 'app-root', |
| 126 | + template: `<div |
| 127 | +>Welcome to {{ |
| 128 | + Angular}}! </div>`, |
| 129 | +}) |
| 130 | +export class App {} |
| 131 | +``` |
| 132 | + |
| 133 | +```angular-html |
| 134 | +<div |
| 135 | +>Welcome to {{ |
| 136 | + Angular}}! </div> |
| 137 | +``` |
| 138 | + |
| 139 | +<!-- Prettier 3.7 --> |
| 140 | +Same as input |
| 141 | + |
| 142 | +<!-- Prettier 3.8 --> |
| 143 | +```angular-ts |
| 144 | +@Component({ |
| 145 | + selector: "app-root", |
| 146 | + template: `<div>Welcome to {{ Angular }}!</div>`, |
| 147 | +}) |
| 148 | +export class App {} |
| 149 | +``` |
| 150 | + |
| 151 | +```angular-html |
| 152 | +<div>Welcome to {{ Angular }}!</div> |
| 153 | +``` |
| 154 | +```` |
0 commit comments