Skip to content

Commit b2238b3

Browse files
authored
V18 (#148)
* Update Angular snippets to use functional guard syntax * chore: update Angular snippets to version 18 * chore: update ngFor trackBy syntax to use a trackBy function
1 parent 7a8b23d commit b2238b3

File tree

5 files changed

+47
-33
lines changed

5 files changed

+47
-33
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
## Angular Snippets Changelog
22

3+
<a name="18.0.0"></a>
4+
5+
# 18.0.0 (2024-07-15)
6+
7+
- removed ngTemplate due to syntax changes
8+
- updated ngContent with squared brackets syntax
9+
- udpated `a-ngFor-trackBy` to call a trackBy function you create (using `a-trackBy`)
10+
- Newer functional guard syntax updates:
11+
- Updated CanActivate guard to be a functional CanActivateFn guard
12+
- Updated CanActivateFn guard to be a functional CanActivateChildFn guard
13+
314
<a name="16.0.1"></a>
415

516
# 16.0.1 (2023-06-15)

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ Alternatively, press `Ctrl`+`Space` (Windows, Linux) or `Cmd`+`Space` (macOS) to
3434
| `a-component-root` | root app component |
3535
| `a-ctor-skip-self` | angular `NgModule`'s `skipself` constructor |
3636
| `a-directive` | directive |
37-
| `a-guard-can-activate` | `CanActivate` guard |
38-
| `a-guard-can-activate-child` | `CanActivateChild` guard |
37+
| `a-guard-can-activate` | `CanActivateFn` guard |
38+
| `a-guard-can-activate-child` | `CanActivateChildFn` guard |
3939
| `a-guard-can-deactivate` | `CanDeactivate` guard |
4040
| `a-guard-can-match` | `CanMatch` guard |
4141
| `a-httpclient-get` | `httpClient.get` with Rx Observable |
@@ -119,7 +119,6 @@ Alternatively, press `Ctrl`+`Space` (Windows, Linux) or `Cmd`+`Space` (macOS) to
119119
| `a-prej` | show the JSON form of a model |
120120
| `a-preja` | show the JSON form of a model, using async |
121121
| `a-ng-container` | `<ng-container>` element |
122-
| `a-ng-template` | `<ng-template>` element |
123122
| `a-ng-content` | `<ng-content>` element |
124123

125124
### VS Code Snippets

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "Angular2",
33
"publisher": "johnpapa",
4-
"displayName": "Angular Snippets (Version 16)",
5-
"description": "Angular version 16 snippets by John Papa",
6-
"version": "16.0.1",
4+
"displayName": "Angular Snippets (Version 18)",
5+
"description": "Angular version 18 snippets by John Papa",
6+
"version": "18.0.0",
77
"icon": "images/angular-shield.png",
88
"galleryBanner": {
99
"color": "#0273D4",

snippets/html.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
},
2222
"ngFor with trackBy": {
2323
"prefix": "a-ngFor-trackBy",
24-
"body": ["*ngFor=\"let ${1:item} of ${2:list}; trackBy:${1:item}.id\"${0}"],
24+
"body": ["*ngFor=\"let ${1:item} of ${2:list}; trackBy:${1:trackByFnName}\"${0}"],
2525
"description": "Angular *ngFor with trackBy"
2626
},
2727
"ngForAsync": {
@@ -126,14 +126,9 @@
126126
"body": ["<ng-container $0></ng-container>"],
127127
"description": "Angular ng-container"
128128
},
129-
"ng-template": {
130-
"prefix": "a-ng-template",
131-
"body": ["<ng-template [ngTemplateOutlet]=\"${1:outlet}\" [ngOutletContext]=\"${2:context}\"></ng-template>"],
132-
"description": "Angular ng-template"
133-
},
134129
"ng-content": {
135130
"prefix": "a-ng-content",
136-
"body": ["<ng-content select=\"${0:selector}\"></ng-content>"],
131+
"body": ["<ng-content select=\"[${0:selector}]\"></ng-content>"],
137132
"description": "Angular ng-content"
138133
}
139134
}

snippets/typescript.json

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -298,41 +298,50 @@
298298
"}"
299299
]
300300
},
301-
"Angular CanActivate Guard": {
301+
"Angular Functional CanActivateFn Guard": {
302302
"prefix": "a-guard-can-activate",
303-
"description": "Angular CanActivate guard",
303+
"description": "Angular Functional CanActivate guard",
304304
"body": [
305305
"import { inject } from '@angular/core';",
306-
"import { ActivatedRouteSnapshot, CanActivateFn, RouterStateSnapshot } from '@angular/router';",
306+
"import {",
307+
" ActivatedRouteSnapshot,",
308+
" CanActivateFn,",
309+
" Router,",
310+
" RouterStateSnapshot,",
311+
"} from '@angular/router';",
307312
"",
308-
"export const ${2:Name}Guard: CanActivateFn = (",
313+
"export const ${1:Name}Guard: CanActivateFn = (",
309314
"\troute: ActivatedRouteSnapshot,",
310315
"\tstate: RouterStateSnapshot",
311-
"\t) => {",
316+
") => {",
317+
"\tconst router = inject(Router);",
312318
"",
313-
"\t\treturn true;$0",
314-
"}"
319+
"\treturn true;$0",
320+
"};"
315321
]
316322
},
317-
"Angular CanActivateChild Guard": {
323+
"Angular Functional CanActivateChildFn Guard": {
318324
"prefix": "a-guard-can-activate-child",
319325
"description": "Angular CanActivateChild guard",
320326
"body": [
321327
"import { inject } from '@angular/core';",
322-
"import { ActivatedRouteSnapshot, CanActivateChildFn, RouterStateSnapshot } from '@angular/router';",
323-
"",
324-
"export const ${2:Name}Guard: CanActivateChildFn = (",
325-
"\troute: ActivatedRouteSnapshot,",
326-
"\tstate: RouterStateSnapshot",
327-
"\t) => {",
328-
"",
329-
"\t\treturn true;$0",
330-
"}"
328+
"import {",
329+
" ActivatedRouteSnapshot,",
330+
" CanActivateChildFn,",
331+
" RouterStateSnapshot,",
332+
"} from '@angular/router';",
333+
"",
334+
"const ${1:Name}Guard: CanActivateChildFn = (",
335+
" route: ActivatedRouteSnapshot,",
336+
" state: RouterStateSnapshot",
337+
") => {",
338+
"\treturn true;$0",
339+
"};"
331340
]
332341
},
333-
"Angular CanMatch Guard": {
342+
"Angular Functional CanMatchFn Guard": {
334343
"prefix": "a-guard-can-match",
335-
"description": "Angular CanMatch guard",
344+
"description": "Angular Functional CanMatchFn guard",
336345
"body": [
337346
"import { inject } from '@angular/core';",
338347
"import { CanMatchFn, Route, Router, UrlSegment } from '@angular/router';",
@@ -347,7 +356,7 @@
347356
},
348357
"Angular CanDeactivate Guard": {
349358
"prefix": "a-guard-can-deactivate",
350-
"description": "Angular CanDeactivate guard",
359+
"description": "Angular Functional CanDeactivateFn guard",
351360
"body": [
352361
"import { inject } from '@angular/core';",
353362
"import { CanDeactivateFn } from '@angular/router';",

0 commit comments

Comments
 (0)