Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tutorial] What is Angular Routing? #282

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d00340e
Code for angular application with multiple routes
ShambhaviVijay Mar 22, 2023
b0dfc4d
Instructions to run Angular app on localhost
ShambhaviVijay Mar 22, 2023
34f6c85
Update readme.md
ShambhaviVijay Mar 22, 2023
aabecdf
Update readme.md
ShambhaviVijay Mar 22, 2023
56a4159
Added the details of What is Angular Routing And How to se it
Sandyah06 Mar 23, 2023
0901a0e
Merge pull request #1 from Sandyah06/patch-1
ShambhaviVijay Mar 23, 2023
d619041
Data passing in Angular basics added in readme.md
smohith79 Mar 23, 2023
18ff451
How to Pass data between angular routes.
Shailaja0205 Mar 23, 2023
0d9a330
Merge pull request #3 from Shailaja0205/patch-2
ShambhaviVijay Mar 23, 2023
264a8ec
Merge pull request #2 from smohith79/patch-1
ShambhaviVijay Mar 23, 2023
b93525e
Update readme.md
ShambhaviVijay Mar 23, 2023
2fc5896
Data passing contents added.
estherjoanna30 Mar 23, 2023
db278bb
Merge pull request #4 from estherjoanna30/patch-1
ShambhaviVijay Mar 23, 2023
9408b39
Angular definition added in readme file.
Martin-20122001 Mar 23, 2023
5d9c89e
Merge pull request #5 from Martin-20122001/patch-1
ShambhaviVijay Mar 23, 2023
cdcb45f
changes done.
ShambhaviVijay Mar 24, 2023
ff94e62
complete
ShambhaviVijay Mar 24, 2023
ca5dc8f
Update readme.md
ShambhaviVijay Mar 24, 2023
294776f
Readme content added.
ShambhaviVijay Mar 24, 2023
57c3ac0
restored
ShambhaviVijay Mar 24, 2023
b080820
changes done
ShambhaviVijay Mar 24, 2023
b5cfb7c
Update README.md
ShambhaviVijay Mar 24, 2023
993ff5b
Update README.md
ShambhaviVijay Mar 24, 2023
4176df0
Update README.md
ShambhaviVijay Mar 24, 2023
6b37703
Update README.md
ShambhaviVijay Mar 24, 2023
14f4aef
Edits done.
ShambhaviVijay Mar 24, 2023
c606023
Update README.md
ShambhaviVijay Mar 24, 2023
5e3a0ed
Update README.md
ShambhaviVijay Mar 24, 2023
11ef2cb
Merge branch 'master' of github.com:ShambhaviVijay/documentationSODA
ShambhaviVijay Mar 24, 2023
ec2a076
Required changes done.
ShambhaviVijay Mar 28, 2023
5d310c7
Update README.md
ShambhaviVijay Mar 28, 2023
cff9708
Update README.md
ShambhaviVijay Mar 28, 2023
5b8bd3d
Update README.md
ShambhaviVijay Mar 28, 2023
8848604
Update README.md
ShambhaviVijay Mar 28, 2023
b06ff95
Update README.md
ShambhaviVijay Mar 28, 2023
b3e5619
msg
Deepikavk00 Mar 31, 2023
9d554ab
Merge pull request #6 from ASHAE847/master
ShambhaviVijay Apr 3, 2023
9700c18
Delete rmu.txt
ShambhaviVijay Apr 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions learning/dashboard/angular_routing/Routing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# ANGULAR


Angular is a development platform, built on TypeScript. As a platform, Angular includes:

A component-based framework for building scalable web applications.

A collection of well-integrated libraries that cover a wide variety of features, including routing, forms management, client-server communication, and more.

A suite of developer tools to help you develop, build, test, and update your code.

With Angular, you're taking advantage of a platform that can scale from single-developer projects to enterprise-level applications. Angular is designed to make updating as straightforward as possible, so take advantage of the latest developments with minimal effort.


## **Angular Installation**


To install Angular using CLI write this line on your terminal,
``` npm install -g @angular/cli ```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Single line code blocks can be written with a single backtick.
Multi-line code blocks can be written with three backticks.


To create workspace named my-app,
``` ng new my-app ```

To run the application enter the following lines on your terminal,
``` cd my-app ```
``` ng serve --open```

After this the Angular application will be launched on your browser at localhost:4200,
(default port for Angular based apps).


# ROUTING IN ANGULAR

- ## **What is Angular Routing**


<p>In a single-page app, you change what the user sees by showing or hiding portions of the display that correspond to particular components, rather than going out to the server to get a new page. As users perform application tasks, they need to move between the different views that you have defined.</p>

<p>To handle the navigation from one view to the next, you use the Angular Router. The Router enables navigation by interpreting a browser URL as an instruction to change the view.</p>

<p>To explore a sample app featuring the router's primary features, see the example below
router.zip file with the reference link. </p>



- ## **How to Use Angular Routes**


Using Angular routes in a single-page application
It describes how to build a single-page application, SPA that uses multiple Angular routes.

In a Single Page Application (SPA), all of your application's functions exist in a single HTML page. As users access your application's features, the browser needs to render only the parts that matter to the user, instead of loading a new page. This pattern can significantly improve your application's user experience.

To define how users navigate through your application, you use routes. Add routes to define how users navigate from one part of your application to another. You can also configure routes to guard against unexpected or unauthorized behavior.


# DATA PASSING


## Data passing in Angular

<ul>
<p>In an Angular application, we may have multiple components with a variety of functionality/features and while developing an application we may come across a situation where we need to share or pass the data from one component to another one, in that case, we can achieve that by using the concept of data sharing between the components, and for that in Angular, there are some provisions or ways to achieve the same.</p>

- ### Methods:

Parent to Child: via Input,

Child to Parent: via Output() and EventEmitter,

Child to Parent: via ViewChild,

Unrelated Components: via a Service.

## Why is data passed between Angular components:


<p>Angular provides component based architecture that allows modularizing the application. It means you can create multiple chunks, and convert your large component to a smaller segment that can be easily maintained. The main advantage to do this is easily understanding the component and maintenance of code. In this scenario, it is important for communication between components or share the data between the component. </p>

<p>Angular provides multiple ways to share the data between the components. Based on your need and kind of component relation, you can select any of the methods. It is recommended to use the service method as it is independent of component relation and helps you to send data to multiple components. </p>

## How to pass the data between angular routes?


The task is to share data variables between two or more controllers by using AngularJS. There are many procedures to achieve this. Here we will discuss the most popular ones.
</li>

### Approach:

1. **Using a service**: We can design a shared service that has the information we want the controllers to exchange. The controllers can inject the service to access the data, and the service may include methods to configure and obtain the data. This method is advised for data exchange across components without a clear parent-child relationship.


2. **Utilizing the @Input() and @Output() decorators**: We can transfer data between parent and child components using the @Input() and @Output() decorators. A parent component can supply data to a child component using the @Input() decorator, and a child component can emit events to a parent component using the @Output() decorator.

3. **ViewChild**: ViewChild can be used to access the properties and methods of the child component from the parent component. When we need to use the data or methods of the child component from the parent component, this way is helpful.

4. **With ngRx**: We can implement a reactive strategy for data sharing between components using the ngRx module. The Redux pattern is the foundation of ngRx, which offers a centralised store for controlling application state. Components can dispatch actions to change the state and subscribe to the shop to get updates when the state changes.

# TUTORIAL APP


Link for a simple Angular application to demonstrate routing: <br>

[ANGULAR-ACE (demo app)](https://github.com/ShambhaviVijay/AngularAce-)


# REFERENCES:

[geekforgeeks](https://www.geeksforgeeks.org) <br>
[Angular official documentation](https://angular.io/guide/router-tutorial) <br>
[C-sharpcorner](https://www.c-sharpcorner.com/article/sharing-the-data-between-components-in-angular) <br>
[dotnettricks](https://www.dotnettricks.com/learn/angular/sharing-data-between-angular-components-methods) <br>
[stackblitz](https://stackblitz.com/run?file=src%2Fapp%2Fapp.component.html) <br>