Angular CLI Basics - ng generate guard


In this video, we cover how to generate guards using the Angular CLI. To generate a guard, you need to run the following command:

ng generate guard guard-name

You can add a number of flags after the component name, depending on what you need. The flags we covered in this section are:

  • --implements
  • --flat

There are three valid values for the --implements flag: CanActivate, CanActivateChild, and CanLoad. You can select one or more of these options by repeating the --implements flag the desired number of times. If you don't use this flag, the CLI will show you a prompt asking you to select at least one value.

For more information on generating guards, and for a list of all the flags available when generating guards, you can check out the docs.

If you'd like more information on route guards, like what they are and what their purpose is, read this section of the Angular documentation.