Skip to content

Creating class-based guards returns error for functional guard #28839

Open
@squinkyplunky

Description

@squinkyplunky

Command

generate

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

When using ng generate guard, it allows me to select multiple options for class based guards. However when I select multiple options, it returns the following error.

"Can only specify one value for implements when generating a functional guard."

ng generate guard auth 
? Which type of guard would you like to create? CanActivate, CanActivateChild, CanDeactivate
Can only specify one value for implements when generating a functional guard.
ng generate guard auth/auth
? Which type of guard would you like to create? CanActivate
CREATE src/app/auth/auth.guard.spec.ts (478 bytes)
CREATE src/app/auth/auth.guard.ts (133 bytes)

Minimal Reproduction

Create new project guard-bug and try to generate guard auth.

ng new guard-bug
? Which stylesheet format would you like to use? Sass (SCSS)     [ https://sass-lang.com/documentation/syntax#scss                ]
? Do you want to enable Server-Side Rendering (SSR) and Static Site Generation (SSG/Prerendering)? no
ng generate guard auth
? Which type of guard would you like to create? CanActivate, CanActivateChild, CanDeactivate, CanMatch
Can only specify one value for implements when generating a functional guard.

Exception or Error

Can only specify one value for implements when generating a functional guard.

Your Environment

ng version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 18.2.11
Node: 22.11.0
Package Manager: npm 10.9.0
OS: win32 x64

Angular: 18.2.11
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1802.11
@angular-devkit/build-angular   18.2.11
@angular-devkit/core            18.2.11
@angular-devkit/schematics      18.2.11
@schematics/angular             18.2.11
rxjs                            7.8.1
typescript                      5.5.4
zone.js                         0.14.10

Anything else relevant?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions