angular2-routing

How to achieve Role Based redirection after login in Angular-5?

血红的双手。 提交于 2019-12-13 03:53:33
问题 I am new to Angular , and i am using Angular-5 . In my application i have 2 screens/components called ' Admin-Dashboard ' and ' HR-Dashboard '. My default route is /Admin-Dashboard have look at following routes: const routes: Routes = [ { path: 'Admin-Dashboard', component: AdminDashboardComponent, canActivate: [AuthGuard] }, { path: HR-Dashboard', component:HRDashboardComponent, canActivate: [AuthGuard] } // otherwise redirect to home { path: '**', redirectTo: '/Admin-Dashboard', canActivate

Angular Routing uncaught error

邮差的信 提交于 2019-12-13 03:35:32
问题 I have the following: I am getting an error saying: compiler.es5.js:1690 Uncaught Error: Template parse errors: Can't bind to 'routerLink' since it isn't a known property of 'a'. (" <div class="navbar-header"> <ul class="nav navbar-nav list-inline"> <li class="home"><a [ERROR ->][routerLink]="['/home']">Login</a></li> <li class="child"><a [routerLink]="['/child']">Child</a>"): ng:///HomeModule/HomeComponent.html@7:25 Can't bind to 'routerLink' since it isn't a known property of 'a'. ("inline"

Angular 2 and MVC routing

浪子不回头ぞ 提交于 2019-12-13 03:33:53
问题 I need some help as I cannot make Angular to call correctly an API inside Visual Studio 2017. Here is part of my code(I have imported and injected everything Angular needs as to work): @Injectable() export class GetCustomerInfoService { constructor(private http: HttpClient) { } getResults() { return this.http.get('http://localhost:65040/api/employees'); } } @Component({ selector: 'apply', templateUrl: './apply.component.html', providers: [GetCustomerInfoService] }) export class ApplyComponent

Angular 2/4 loading scripts dynamically

∥☆過路亽.° 提交于 2019-12-13 02:52:32
问题 In angular 2 one can load CSS styles depending on the component. However, there is no corresponding way to load script files. I am currently loading all scripts on the base page of my single page applications but that results in optimization issues. What is the advised way of loading scripts for an Angular 2/4 component. 回答1: Well you can load script dynamically in any component. Here is the solution : Create a service in which you'll have js file. // script.store.ts interface Scripts { name:

In Angular2 how do you change a sidebar based on the active route?

こ雲淡風輕ζ 提交于 2019-12-13 02:27:13
问题 I'm writing an SPA using Angular 2 (RC5) and Typescript. I have a main navbar on top (using Bootstrap 4 Alpha 3), and a custom-designed sidebar. Here's a pic: The intention here is to navigate to a main "application" using the top navbar. Currently I have 3 main apps mapped out - Tracker, Proboard and Equipment. Once a main application has been activated, the links on the sidebar would change. In the picture above, the sidebar is showing links for the 'Proboard' application. How can I change

routerCanReuse and routerOnReuse is not called when route changes

谁说我不能喝 提交于 2019-12-13 01:17:29
问题 I am trying to figure out the OnReuse and CanReuse parts of Angular2's Router and I'm hitting a wall. I modeled my code after the docs here, but for some reason I can't get the methods to call when the route changes. Not sure what I'm doing wrong. Here's my code: app.component.ts import {Component, OnInit, NgZone, View} from 'angular2/core'; import {Location, RouteConfig, RouterLink, ROUTER_DIRECTIVES} from 'angular2/router'; import {ProductTable} from './product-table.component'; import

How to define lazy Module paths in angular2 and load specific module for that path

依然范特西╮ 提交于 2019-12-13 00:37:51
问题 I have different components and routes based on roles. Now i have defined routes as for certain components as below Login Module path: '', loadChildren:'app/login/login.module#LoginModule'; Register Module path:'', loadChildren: 'app/register/register.module#LoginModule' Dashboard Module path:'' loadChildren:'app/dashboard/dashboard.module#dashboardModule' User Profile Module path:'' loadChildren:'app/user-profile/user-profile.module#UserProfileModule' Now whenever I navigate to login or

Angular2 don't load external js file when i change the view

試著忘記壹切 提交于 2019-12-13 00:16:50
问题 I am still learning Angular 2 so i may be doing something wrong over here. I have a HTML/CSS template and i am trying to make it work with Angular 2. I have created an Angular2 project with few components... in the app.component.html i have my menu <ul class="clearfix"> <li><a [routerLink]="['/']">Home</a></li> <li><a [routerLink]="['/link1']">Link1</a></li> <li><a [routerLink]="['/link2']">Link2</a> </li> </ul> When i click on one item of the menu it changes the view to the component i made

Angular 2 - how to pass data to a child component without rendering the child component twice?

余生颓废 提交于 2019-12-12 23:25:36
问题 I want to pass an object from app.component to a child component (home.component). Am I using routing the wrong way and that's why the child component I want to pass the object to is being rendered twice? How can I avoid it? I guess that might also be the reason why that object is undefined the second time the component is rendered. I've been googling for several days now and nothing seems to work. I was following a video tutorial but it was based on Angular 2 RC3 or earlier I guess. I am

Angular2 RC5 lazy load routing can´t find module

早过忘川 提交于 2019-12-12 23:13:42
问题 I'm trying to implement RC5 changes in my app and I'm getting some trouble when lazy loading modules in my routing. This is the structure in my app for the affected files: /app /components/meda/meda.module.ts /components/meda/meda.routing.ts app.routing.ts And this is my app.routing.ts const routes: Routes = [ { path: '', redirectTo: 'init', pathMatch: 'full' }, { path: 'init', loadChildren: './components/init/init.module#InitModule' }, { path: 'meda', loadChildren: './components/meda/meda