Тёмный

Angular Routing 

kudvenkat
Подписаться 829 тыс.
Просмотров 42 тыс.
50% 1

Implementing routing in an Angular application involves many small steps. Angular CLI does a pretty good job in having some of these routing steps implemented out of the box by just using --routing option.
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our RU-vid channel. Hope you can help.
/ @aarvikitchen5572
Before we discuss, how we can use Angular CLI to implement routing let's setup routing manually so we understand all the moving parts as far as implementing routing is concerned.
Using the following command, first create a brand new Angular project using the Angular CLI.
ng new employeeManagement
We named it employeeManagement. Let's assume we are using this application to manage employees. Out of the box, Angular CLI has created the root component - AppComponent. In addition let's create the following 3 components
home : ng g c home
employees : ng g c employees
pageNotFound : ng g c pageNotFound
Steps to implement routing in Angular
Step 1 : Set base href in the application host page - index.html
Step 2 : Import the RouterModule into the application root module AppModule. The Router Module contains the Router service and Router directives such as (RouterLink, RouterLinkActive, RouterOutlet etc). So for us to be able to implement routing, we first need to import the Router Module in our AppModule.
Step 3 : Configure the application routes.
import { RouterModule, Routes } from '@angular/router';
// Each route maps a URL path to a component
// The 3rd route specifies the route to redirect to if the path
// is empty. In our case we are redirecting to /home
// The 4th route (**) is the wildcard route. This route is used
// if the requested URL doesn't match any other routes already defined
const appRoutes: Routes = [
{ path: 'home', component: HomeComponent },
{ path: 'employees', component: EmployeesComponent },
{ path: '', redirectTo: '/home', pathMatch: 'full' },
{ path: '**', component: PageNotFoundComponent }
];
// To let the router know about the routes configured above,
// pass "appRoutes" constant to forRoot(appRoutes) method
// We also have forChild() method. We will discuss the difference
// and when to use one over the other in our upcoming videos
@NgModule({
declarations: [...
],
imports: [
BrowserModule,
RouterModule.forRoot(appRoutes)
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Step 4 : Specify where you want the routed component view template to be displayed using the router-outlet directive
Step 5 : Tie the routes to application menu.
To install bootstrap execute the following npm command
npm install bootstrap@3 --save
Once Bootstrap is installed, open .angular-cli.json file and specify the path to the Bootstrap stylesheet in the styles property as shown below.
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"styles.css"]
At this point Routing should be working as expected.
The following are the directives provided by the RouterModule
routerLink
Tells the router where to navigate when the user clicks the navigation link
routerLinkActive
When a route is active the routerLinkActive directive adds the active CSS class. When a route becomes inactive, the routerLinkActive directive removes the active CSS class.
The routerLinkActive directive can be applied on the link element itself or it's parent. In this example, for the active route styling to work correctly, routerLinkActive directive must be applied on the list item element and not the anchor element.
router-outlet
Specifies the location at which the routed component view template should be displayed
At the moment routing is implemented in the root module - AppModule. However, for separation of concerns and maintainability, it is better to implement routing in a separate Routing module and then import that routing module in the AppModule. In a later video, we will discuss how to move routing into it's own routing module.
Text version of the video
csharp-video-tutorials.blogspo...
Slides
csharp-video-tutorials.blogspo...
Angular CLI Tutorial
• What is Angular CLI
Angular CLI Text articles & Slides
csharp-video-tutorials.blogspo...
All Dot Net and SQL Server Tutorials in English
ru-vid.com...
All Dot Net and SQL Server Tutorials in Arabic
/ kudvenkatarabic

Наука

Опубликовано:

 

6 ноя 2017

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 27   
@phaobi
@phaobi 6 лет назад
Sir Venkat, You are really very great and you are contributing great things to the world, God bless you abundantly. But Sir if you can guide in the line of ethical hacking then we will learn more and more from you cos your way of explanation is so simply good and great.Have a great day Sir...!!!
@deepakpawar8202
@deepakpawar8202 6 лет назад
Very Helpful.... Thank you Sir
@sashidhar2285
@sashidhar2285 4 года назад
Should be "node_modules/bootstrap/dist/css/bootstrap.css" instead of ../node_modules in Angular 8
@chaitrask8009
@chaitrask8009 4 года назад
very helpfull video
@chrisstephens983
@chrisstephens983 6 лет назад
This tutorial is so basic the Angular docs cover this very well already, I'd like if it went into more programatic routing and nested routes etc.
@sashidhar2285
@sashidhar2285 4 года назад
Did you see how he mentioned in the playlist title? it is for beginners!
@vijaykumar883
@vijaykumar883 5 лет назад
How To Reload A Component From Another Component For e.g. On A Page I Have 2 Componenet CMP-1 AND CMP-2 after few changes on CMP-1 Data should reflect on CMP-2
@gajamjyothi4250
@gajamjyothi4250 6 лет назад
Hi , Could please help how to call external url's using routing application,that external page should open within the same application not in new page
@rameshGuptaranu
@rameshGuptaranu 6 лет назад
Sir in my project there is not any angular.cli.json file, only have angular.json file I installed the bootstrap and it shows in node_module folder. In angular.json file i put the path of bootstrap css file but out put is not showing as yours
@fullstackdeveloper4228
@fullstackdeveloper4228 6 лет назад
excellent tutorial....
@Csharp-video-tutorialsBlogspot
Thank you.
@himanshu2709
@himanshu2709 4 года назад
Hi Venkat. I have been following your tutorial series. ASP.Net , ASP.Net MVC, JavaScript, JQuery, Angular 2 and now Angular CLI.. Thanks a lot. Your tutorials are very descriptive and helpful.. I was facing few issues while trying to practice sample under video 17. I am using Angular CLI: 9.1.1 and Node: 13.12.0. I do not have angular-cli.json in the generated project. Although I do have angular.json. I added "../bootstrap/dist/css/bootstrap.min.css" to Styles section under angular.json. Bootstrap style were however not loading after the above step. I did some googling and found below solution. =================================== Step 1. Inside .angular-cli.json file "styles": [ "styles.css", "../node_modules/bootstrap/dist/css/bootstrap.min.css" ] Remove "../node_modules/bootstrap/dist/css/bootstrap.min.css" Step 2. Go to styles.css Import bootstrap by adding this line @import "~bootstrap/dist/css/bootstrap.css"; ============================================ After this change bootstrap style got loaded in my project and started working.
@aakashggujju
@aakashggujju 4 года назад
Thanks a lot buddy I too faced the similar issue
@peterl1699
@peterl1699 6 лет назад
Great one. Angular material 2 next 🙂
@Csharp-video-tutorialsBlogspot
Sure, I will cover Angular Material as soon as practically possible.
@josephregallis3394
@josephregallis3394 6 лет назад
I had a problem with the path for Bootstrap. I had to use "C:/employeeManagement/node_modules/bootstrap/dist/css/bootstrap.min.css" to get it to work. I tried using the path you gave us but that would not work. I kept getting an error that the module could not be found. I put this in here if anyone else runs into this error.
@CodingSquid
@CodingSquid 5 лет назад
I was having the same problem. Looking at the error from ng serve, it looked like I was going back one two many levels in the directory tree with the ../ so I used ./ instead. "styles": [ "./node_modules/bootstrap/dist/css/bootstrap.min.css", "src/styles.css" ] Maybe this helps the next person.
@sudhakarkgr3105
@sudhakarkgr3105 6 лет назад
Excellent. Please do more videos in angular 4
@Csharp-video-tutorialsBlogspot
Sure, I will. As you might already know, the version that we are using for this Angular Routing project is Angular 4. If you look at package.json file in the project you will notice we are using Angular 4. On my machine it it Angular 4.2.4.
@vijaykumar883
@vijaykumar883 5 лет назад
How Routing Same Router with Different params Not Reflecting any Changes why any reasons For Example #/formControlViewData?id=2&formName=Employee #/formControlViewData?id=3&formName=User%20Details On Router formControlViewData Reading Param on First render it is reading Param But when Triggering same Route with Param changes it not reflecting. any specfic reasons
@ashishkumarmaurya4177
@ashishkumarmaurya4177 6 лет назад
routerLink directive giving parsing error ERROR, ERROR CONTEXT
@sundali61
@sundali61 6 лет назад
Not working properly. imports: [ BrowserModule,RouterModule.forRoot(appRoutes) ], Please add following export in appModule exports: [RouterModule],
@prafullawankhede4582
@prafullawankhede4582 4 года назад
npm install bootstarp@3 --save throws error as "error No valid versions available for bootstarp"
@ramyachowdarypolavarapu3257
just remove @ version and try
@sashidhar2285
@sashidhar2285 4 года назад
Angular-cli.json is replaced with angular.json
@muditsharma4010
@muditsharma4010 5 лет назад
Good one but Poor video quality.
@Csharp-video-tutorialsBlogspot
Hello Mudit - The quality of the video depends on your internet connection bandwidth. All the videos are uploaded in HD quality. To improve the video quality, click the settings button that is present at the lower bottom right hand corner of the RU-vid player.
Далее
How routing works in angular
6:19
Просмотров 28 тыс.
Angular 2 routing tutorial
17:38
Просмотров 129 тыс.
Joy and Anxiety Mood (Inside Out Animation)
00:13
Просмотров 1,1 млн
Дьявол - ТРЕШ ОБЗОР на фильм
19:10
Angular services tutorial
13:52
Просмотров 170 тыс.
Angular reactive forms
10:49
Просмотров 203 тыс.
Routing and Navigation in Angular | Mosh
24:32
Просмотров 284 тыс.
Angular dev build vs prod build
10:46
Просмотров 51 тыс.
Angular resolve guard
10:02
Просмотров 43 тыс.
Angular component lifecycle hooks
13:51
Просмотров 217 тыс.
Angular aot vs jit
9:41
Просмотров 59 тыс.
APPLE дают это нам БЕСПЛАТНО!
1:01
Просмотров 604 тыс.
Acer Predator Тараканьи Бега!
1:00
Просмотров 480 тыс.