Search⌘ K

User Creation

Explore how to build a user signup page in Angular by creating an authentication service, interacting with an API for user creation, and verifying data. This lesson guides you through setting up routing, testing the service, and ensuring user data is stored correctly.

Create auth service

The first thing we’ll do is create the service we’ll use to handle user creation and authentication.

ng g service services/auth/auth
  • This command creates a /services directory with another directory, /auth, that contains our service and its associated test file.
  • We create this /services directory to hold all our services so they don’t pollute our src/app directory.

If you’re curious about what the CLI will generate for you, there’s a handy flag -d, which stands for dry run that you can add to your CLI commands to run the command without making any changes to your code.

ng g service services/auth/auth -d

This will list the files that would have been created or updated had the same command been run without the flag. It’s useful in cases like this where we’re creating new directories with the CLI and we want to double-check that everything is right before we create the files. We’ll take another look at this in the next section.

Terminal 1
Terminal
Loading...

The above command ng g service services/auth/auth has created two ...