angular2-routing

Angular 2: getting RouteParams from parent component

*爱你&永不变心* 提交于 2019-12-08 15:30:22
问题 How do I get the RouteParams from a parent component? App.ts : @Component({ ... }) @RouteConfig([ {path: '/', component: HomeComponent, as: 'Home'}, {path: '/:username/...', component: ParentComponent, as: 'Parent'} ]) export class HomeComponent { ... } And then, in the ParentComponent , I can easily get my username param and set the child routes. Parent.ts : @Component({ ... }) @RouteConfig([ { path: '/child-1', component: ChildOneComponent, as: 'ChildOne' }, { path: '/child-2', component:

returning null in Angular 2 custom validator throwing an error

依然范特西╮ 提交于 2019-12-08 13:34:55
问题 <div class="col-md-6"> <div class="form-group"> <h6>Email Address</h6> <input type="text" class="form-control" name="email" formControlName='Bemail' required> <div [hidden]="BusinessInfoForm.controls.Bemail.valid || (BusinessInfoForm.controls.Bemail.pristine && !submitted)" > <p class="text-danger" [hidden]="!BusinessInfoForm.controls.Bemail.errors.required">mailAddressis required.</p> <p class="text-danger" [hidden]="!BusinessInfoForm.controls.Bemail.errors.incorrectMailFormat">Email format

How to check the element is in viewport on angular 2?

不问归期 提交于 2019-12-08 13:33:27
问题 How to check element is in viewport in angular 2?. I have tried with many npm packages. But not working. How to check the element is in viewport?. I want to call API on page scroll if element is in viewport? I have three tabs. I have to check if tab is active and element is in viewport. How to check? 回答1: I used ' jQuery-viewport-checker ' to perform various tasks if elements are on viewport. It worked for me. This may help you: Follow this if you don't have "jQuery" working in your angular 2

Angular 5 child routes adding parentheses to the route

笑着哭i 提交于 2019-12-08 13:12:29
I have an Angular 5 application with a series of components. Some of the components are children of others, and some are not. I would like the application to have a structure such as: */my-account/overview // homepage */my-account/my-stuff */profile */non-default I have a DefaultComponent that contains some generic elements such as site navigation that I would like to be present on most of the pages (everything except for the */non-default route/component). My routing module defines the routes below: export const routes: Routes = [ { path: '', redirectTo: 'my-account', pathMatch: 'full' }, //

How to change only params of route in angular2?

故事扮演 提交于 2019-12-08 11:18:59
问题 I have a method add() on component that is called in this route: 'model/:id' . Now, i want to add a new model, and for do this, need change the route to: 'model/0' ; add(){ this.route.navigate(['model','0']); } I need to do this with the 'model' route dynamically, because the route can change, it's possible ? 回答1: In your constructor import ActivatedRoute construction(private route: ActivatedRoute, ...) {} add() { this.router.navigate(['../', '0'], {relativeTo: this.route}); } 回答2: Try this

set route for sitemap on angular2 universal

懵懂的女人 提交于 2019-12-08 08:16:58
问题 How can we set the route so that sitemap can be access through URL : < domain_name >/sitemap.xml My app routing module is kind of like this :- export function getHomeModule() { return System.import('./+home/home.module' + (process.env.AOT ? '.ngfactory' : '')) .then(mod => mod[(process.env.AOT ? 'HomeModuleNgFactory' : 'HomeModule')]); } @NgModule({ imports: [ RouterModule.forRoot([ { path: '', redirectTo: '/home', pathMatch: 'full' } ], {preloadingStrategy: PreloadAllModules}) ], }) I am

How to reload/refresh all the current components in angular2?

故事扮演 提交于 2019-12-08 07:46:37
问题 Hi I am using the new alpha component router of angularjs2 https://angular.io/docs/ts/latest/guide/router.html I have a modal that authenticate a user then creates a JWT in localstorage which holds the user's needed info. My problem is that if the user is looking on the /home path there are stuff there that only visible to logged-in users, but after he log in through the modal he has to refresh the page so the components will refresh and show the correct logged-in information Is there a way

Angular 2 - issue with bootstrap nav <li><a href=“#header”></a></li> in routing set up

不羁岁月 提交于 2019-12-08 07:07:09
问题 am trying to converting normal bootstrap page into components in Angular 2. am actually facing issues when constructing navigation. initially the tags <li><a href></a></li> is like below <div id="header" class="shadow"> <!-- Navigation --> <nav> <div class="nav nav-wrapper navbar-fixed-top"> <div class="container-fluid"> <!-- Menu Option --> <ul class="nav-justified hide-on-med-and-down"> <li><a href="#header">About</a></li> <li><a href="#prodcutInfo">Prod.Info</a></li> <div id="side-nav">

Angular 2 - router: How to animate page transition during route resolve

最后都变了- 提交于 2019-12-08 07:00:49
问题 Currently inside my NG2 app I'm using a resolver , that makes a connection to signalr. I have configured the resolver inside my route config, so when navigation to the destination page, the resolve function is called accordingly. I've managed to show an animation when the destination page is initialized. However, I would like to show an ' is-busy ' like animation DURING the resolving of my resolver, but I don't know how to do this. Any suggestions? This is my current setup: //resolver.ts

Dynamically adding routes in Angular

半世苍凉 提交于 2019-12-08 06:13:28
问题 I am trying to dynamically add routes in my angular app const routes: Routes = [ // my static routes ]; let sections = localStorage.getItem('sections'); if (sections) { JSON.parse(sections).forEach(section => { routes.push({ path: section.route, component: SectionComponent }); }); } @NgModule({ imports: [RouterModule.forRoot(routes)], exports: [RouterModule] }) export class AppRoutingModule { } This works fine in dev but in a production build the dynamic route are not added. I have tried