angular
Overview
Angular is a TypeScript-based web application framework developed by Google. It provides a comprehensive solution for building dynamic single-page applications with a component-based architecture.
Quick Start
Create Repository from Template
On your dashboard, go to the Tools & Deployment tab. Click the "New Repository" button, select the Angular template from the dropdown, enter a repository name and subdomain, then click "Create Repository".
Clone Your Repository
git clone https://<git-server>/<username>/<repo-name>.git
cd <repo-name>
Install Dependencies
npm install
Start Development Server
npm start
Open http://localhost:4200 in your browser.
Build & Push
npm run build
git add .
git commit -m "Initial setup"
git push origin main
Local Development with Docker
If you don't have Node.js installed locally, you can use Docker to run Angular commands. The project includes a Dockerfile for production builds.
Prerequisites
Install Docker Desktop for your operating system (Windows, Mac, or Linux).
Running Commands with Docker
# Run npm install
docker run --rm -v $(pwd):/app -w /app node:lts-alpine npm install
# Run development server (accessible at localhost:4200)
docker run --rm -v $(pwd):/app -w /app -p 4200:4200 node:lts-alpine npm start
# Build for production
docker run --rm -v $(pwd):/app -w /app node:lts-alpine npm run build
Project Structure
Understanding where files are located:
├── src/
│ ├── app/
│ │ ├── app.component.ts # Root component
│ │ ├── app.component.html # Root template
│ │ ├── app.component.css # Component styles
│ │ ├── app.config.ts # App configuration
│ │ └── app.routes.ts # Routing configuration
│ ├── index.html # Main HTML file
│ ├── main.ts # Application entry point
│ └── styles.css # Global styles (Tailwind)
├── public/ # Static assets
├── angular.json # Angular CLI configuration
├── package.json # Dependencies and scripts
├── tailwind.config.js # Tailwind CSS configuration
├── tsconfig.json # TypeScript configuration
└── Dockerfile # Docker build configuration
Common Tasks
Creating a New Component
ng generate component components/my-component
Creating a New Service
ng generate service services/my-service
Adding a Route
Edit src/app/app.routes.ts:
import { Routes } from '@angular/router';
import { HomeComponent } from './components/home/home.component';
export const routes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'about', component: AboutComponent }
];
Using Tailwind CSS
Tailwind is pre-configured. Use classes directly in your templates:
<div class="bg-blue-500 text-white p-4 rounded-lg">
Hello Tailwind!
</div>
Useful Commands
npm start
Start development server (port 4200)
npm run build
Build for production
npm test
Run unit tests
ng generate component
Create a new component
ng generate service
Create a new service
ng generate --help
List all available generators
Troubleshooting
npm install fails with permission errors
Cause: Permission issues with npm cache or node_modules.
Solution: Delete node_modules folder and package-lock.json, then run npm install again.
Port 4200 already in use
Cause: Another process is using port 4200.
Solution: Use a different port: ng serve --port 4201 or stop the other process.
Module not found errors
Cause: Dependencies not installed or corrupted.
Solution: Run npm install to install all dependencies.
Changes not reflecting in browser
Cause: Browser cache or live reload not working.
Solution: Hard refresh (Ctrl+Shift+R or Cmd+Shift+R) or restart the dev server.
Build fails after deployment
Cause: Build errors or missing dependencies.
Solution: Run npm run build locally first to check for errors before pushing.
Deployment Workflow
Every time you push code to Git, your application is automatically built and deployed:
Your deployed application URL follows this format:
https://<your-subdomain>-<repo-name>.<session-domain>
Example: https://student01-module-a.demo.nstrim.app