-
Notifications
You must be signed in to change notification settings - Fork 269
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
ShambhaviVijay
wants to merge
38
commits into
sodafoundation:master
Choose a base branch
from
ShambhaviVijay:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
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 b0dfc4d
Instructions to run Angular app on localhost
ShambhaviVijay 34f6c85
Update readme.md
ShambhaviVijay aabecdf
Update readme.md
ShambhaviVijay 56a4159
Added the details of What is Angular Routing And How to se it
Sandyah06 0901a0e
Merge pull request #1 from Sandyah06/patch-1
ShambhaviVijay d619041
Data passing in Angular basics added in readme.md
smohith79 18ff451
How to Pass data between angular routes.
Shailaja0205 0d9a330
Merge pull request #3 from Shailaja0205/patch-2
ShambhaviVijay 264a8ec
Merge pull request #2 from smohith79/patch-1
ShambhaviVijay b93525e
Update readme.md
ShambhaviVijay 2fc5896
Data passing contents added.
estherjoanna30 db278bb
Merge pull request #4 from estherjoanna30/patch-1
ShambhaviVijay 9408b39
Angular definition added in readme file.
Martin-20122001 5d9c89e
Merge pull request #5 from Martin-20122001/patch-1
ShambhaviVijay cdcb45f
changes done.
ShambhaviVijay ff94e62
complete
ShambhaviVijay ca5dc8f
Update readme.md
ShambhaviVijay 294776f
Readme content added.
ShambhaviVijay 57c3ac0
restored
ShambhaviVijay b080820
changes done
ShambhaviVijay b5cfb7c
Update README.md
ShambhaviVijay 993ff5b
Update README.md
ShambhaviVijay 4176df0
Update README.md
ShambhaviVijay 6b37703
Update README.md
ShambhaviVijay 14f4aef
Edits done.
ShambhaviVijay c606023
Update README.md
ShambhaviVijay 5e3a0ed
Update README.md
ShambhaviVijay 11ef2cb
Merge branch 'master' of github.com:ShambhaviVijay/documentationSODA
ShambhaviVijay ec2a076
Required changes done.
ShambhaviVijay 5d310c7
Update README.md
ShambhaviVijay cff9708
Update README.md
ShambhaviVijay 5b8bd3d
Update README.md
ShambhaviVijay 8848604
Update README.md
ShambhaviVijay b06ff95
Update README.md
ShambhaviVijay b3e5619
msg
Deepikavk00 9d554ab
Merge pull request #6 from ASHAE847/master
ShambhaviVijay 9700c18
Delete rmu.txt
ShambhaviVijay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ``` | ||
|
||
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> | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.