Step 1
ng new directive-demo
cd directive-demo
Step 2:
Open app.component.ts file and puth the contents as below:
@Component({
---------------------------------------------------------------------------------------------------------------
Open app.component.html and put the contents as follows:
---------------------------------------------------------------------------------------------------------------
Open the file app.component.css and the make the contents as shown:
---------------------------------------------------------------------------------------------------------------
ng serve to see the browser similar to as shown below
๐ Getting Started with Angular Material (The Fun Way!)
So, you want to make your Angular app look cool and modern using Angular Material? You're in the right place! Follow these super easy steps, and letโs get that Material magic going! โจ
๐ ๏ธ Step 1: Install Node.js (If You Havenโt Already)
Before we dive into Angular, you need Node.js. Download and install it from here: ๐ Node.js Official Website
After installation, check if everything is set up properly:
ng -v # Check Angular version
node -v # Check Node.js version
npm -v # Check NPM version
๐ If you see version numbers, youโre good to go!
๐ Step 2: Install Angular CLI Globally
Now, letโs get Angular CLI installed globally so we can use it anywhere.
npm install -g @angular/cli
Once done, confirm the installation:
ng version
If you see the Angular CLI version, you're golden! ๐
๐ง Step 3: Fix Execution Policy Issues (Windows Only)
If you get errors about scripts being blocked, fix it with this command:
Get-ExecutionPolicy -List
Set-ExecutionPolicy Unrestricted -Scope CurrentUser
๐๏ธ Step 4: Create a New Angular Project
Let's create our Material magic project:
ng new matdemo
- When asked about CSS, choose CSS (or SCSS if you're feeling fancy!).
- When asked "Do you want server-side rendering?", just say No.
โ
Once done, open package.json
and check everything looks good.
Now, letโs move into our project folder:
cd matdemo
๐ Step 5: Serve the Angular App
Time to check if our app is running smoothly!
ng serve -o
This will launch your app in the browser at:
๐ http://localhost:4200/
Now, letโs open it inside Visual Studio Code:
- Copy
http://localhost:4200/
- Open VS Code, right-click on the file explorer and choose "Split Right" for multitasking!
๐จ Step 6: Add Angular Material
Time to make things look cool! Run this command to add Angular Material:
ng add @angular/material
- Choose Y when it asks about Angular Material.
- Pick the default theme (or go crazy and choose another one!).
- Say Yes for Typography.
- Say Yes for Animations.
โ
Check package.json
to make sure Material is installed.
โ
Also, check main.ts
, app.config.ts
, and app.component.ts
for Material setup.
๐๏ธ Step 7: Add Material Components to Your App
Update app.component.ts
Add Material Slide Toggle Module:
import { Component } from '@angular/core';
import { MatSlideToggleModule } from '@angular/material/slide-toggle';
@Component({
selector: 'app-root',
standalone: true,
imports: [MatSlideToggleModule],
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent { }
Update app.component.html
Now, add some Material UI elements:
<mat-slide-toggle></mat-slide-toggle><br>
<input matInput placeholder="Enter Name" type="text" value="IMMSS"><br>
<button mat-button>Basic</button>
<button mat-raised-button>Raised</button>
<button mat-stroked-button>Stroked</button>
๐ Boom! Youโve just added your first Angular Material components!
๐ฅ Step 8: Add Material Icons
Want some cool icons? Add MatIconModule inside app.component.ts
:
import { MatIconModule } from '@angular/material/icon';
Now, use it in HTML:
<mat-icon>home</mat-icon>
๐ฏ Final Step: Restart Your Angular Server
If things donโt update, restart your Angular server:
ng serve -o
๐ Check your browser โ you should see your stunning Material UI!
๐ Level Up: Explore More!
Want to add even more Material awesomeness? Check out: ๐ Material Angular Official Docs ๐ Awesome YouTube Tutorial
Happy Coding! ๐๐ฅ
------------------------------------------------------------------------------------------------------------------
You may face some Challenges! Don't hesitate to contact me 4 any breakups!๐
No comments:
Post a Comment