Guided Exercise - Angular App with API Data Fetching - Magical Users #159
akash-coded
started this conversation in
Tasks
Replies: 2 comments 1 reply
-
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Let's recreate the "Magical Users" app in Angular. As we go along, I'll explain each Angular concept in-depth, and contrast it with the React approach from the given exercise.
Creating "Magical Users" App in Angular
Step 1: Setup
cd magical-users
Open your browser and go to
http://localhost:4200
to see the default Angular app running.Step 2: Install Axios
HttpClient
module for HTTP requests. So, we'll set that up.First, open
src/app/app.module.ts
and importHttpClientModule
from@angular/common/http
. AddHttpClientModule
to theimports
array.Step 3: Clear the default project and Fetch Users
src/App.js
and fetched users using Axios.Open
src/app/app.component.ts
:Then, in
src/app/app.component.html
:Step 4: Create UserCard component
UserCard.js
.In
src/app/user-card/user-card.component.ts
:In
src/app/user-card/user-card.component.html
:Step 5: Add some styles
The styling remains largely the same. Add the provided styles to
src/styles.css
.Step 6: Run the app
With
ng serve
running, visithttp://localhost:4200
. You should see the app functioning similarly to the React version.Angular Concepts & Contrasts with React:
Angular CLI vs. Create React App:
Angular Components vs. React Components:
HttpClient vs. Axios:
HttpClient
module.State & Lifecycle:
useState
and lifecycle methods/hooks likeuseEffect
.ngOnInit
(similar tocomponentDidMount
) and properties for state.Input & Props:
@Input()
decorator to receive data from parent components.Event Handling:
onClick
).(click)
).Conditional Rendering:
&&
or ternary operators).*ngIf
.Styling:
By the end of this exercise, React freshers should grasp Angular's architecture, data flow, component structure, and HTTP mechanisms. Contrasting Angular and React provides a solid understanding, facilitating the transition between frameworks.
Beta Was this translation helpful? Give feedback.
All reactions