angular2-routing

Using regex for path value of routes in angular2

六眼飞鱼酱① 提交于 2019-12-01 04:48:22
问题 I want to configure route for my angular2 application. My URL needs to be like this: http://domain_name/constant_value/variable_value/constant_value The url can be like following examples: http://localhost/myhouse/floor1/mirror http://localhost/myhouse/floor1/room1/mirror http://localhost/myhouse/floor1/room1/bathroom/mirror Here the routes /myhouse and /mirror are constant. But the middle part can be anything like /floor1 or /floor2/something/something/.... How can i define a route for that

Add element with RouterLink dynamically

对着背影说爱祢 提交于 2019-12-01 04:13:56
When i put an anchor element in someweher in a angular 2 Component like this, <a [routerLink]="['/LoggedIn/Profile']">Static Link</a> everything is working fine. When clicking the link, the angular router routes me to the target component. Now i would like to add the same link dynamically. Somewhere in my app i have a "notification component", which single responsibility is to display notifications. The notifications component does something like this: <div [innerHTML]="notification.content"></div> where notification.content is the string variable in the NotificationComponent class, and

Angular2- Update UI after deleting

a 夏天 提交于 2019-12-01 04:11:30
问题 I have an angular2 app whose backend is in java. I have a list of customers. When i click to remove a customer , the customer is removed but the list does not update. If i manually refresh the page then the list updates. I tried routing to the list component in the subscribe of delete method but that does not work. list-customers.component.html <tr [class.warning]="customer.isDefault == 1" *ngFor="let customer of customers | orderBy:['firstName'] | search:searchCustomer.value;let serial =

Angular 2 Router - Named outlets

好久不见. 提交于 2019-12-01 04:07:06
The documentation is not very good, but I am trying to have different router outlets on the same page/route. I have this in my app.component.html <router-outlet></router-outlet> <router-outlet name="dashboard"></router-outlet> My app.routes.ts { path: '', component: HomeComponent, outlet: 'primary' }, { path: '', component: DashboardComponent, outlet: 'dashboard' }, { path: '**', redirectTo: '404' } So on my startpage (i.e "example.com", not "example.com;dashboard:dashboard") I want to show the Homecomponent in the primary router outlet and my Dashboardcomponent in the Dashboard outlet. That

Angular 4 Component ngOnInit not called on each route request

别等时光非礼了梦想. 提交于 2019-12-01 04:06:58
I just recently started diving into Angular 4 coming from Angular 1.5. I'm working with user routes and pulling API data from a service into a user component. The component seems to stay static unlike controllers in 1.* where they were refreshed on each request. Is there anyway to have the ngOnInit function called on each new route request? My user component class: // url structure: /user/:id export class UserComponent implements OnInit { constructor(private route: ActivatedRoute) {} ngOnInit() { // doesn't log new id on route change let id = this.route.snapshot.params['id']; console.log(id);

Cannot match any routes

妖精的绣舞 提交于 2019-12-01 02:25:17
My component shows up but i get an error message when the page is loaded. I can't seem to solve the error message at all after looking at a bunch of resources. Error EXCEPTION: Error: Uncaught (in promise): Cannot match any routes. Current segment: 'index.html'. Available routes: ['/login']. main.component.ts is in index.html and as soon as the page loads it shows the above error message. import { Component } from '@angular/core'; import { Routes, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from '@angular/router'; import { LoginComponent } from './login/login.component'; @Component({ selector: 'main

GTM randomly skips initial pageview in single page app

偶尔善良 提交于 2019-12-01 02:21:10
I have Pageview tag in Google Tag Manager that tracks SPA pageviews, identical to the one described in this guide . Basically it is Universal Analytics with linked Google Analytics ID that is triggered on History Change (at some point All Pages trigger was also added with no success). In my current app GTM skips Pageview tag on initial pageviews on all routes that don't have async resolvers. Usually the routes fire the tag sometimes (1 of 5 times), this may vary a bit depending on conditions (cached vs uncached, localhost vs production). On the routes that have resolvers with long durations (>

Angular 2 Router - Named outlets

♀尐吖头ヾ 提交于 2019-12-01 02:09:04
问题 The documentation is not very good, but I am trying to have different router outlets on the same page/route. I have this in my app.component.html <router-outlet></router-outlet> <router-outlet name="dashboard"></router-outlet> My app.routes.ts { path: '', component: HomeComponent, outlet: 'primary' }, { path: '', component: DashboardComponent, outlet: 'dashboard' }, { path: '**', redirectTo: '404' } So on my startpage (i.e "example.com", not "example.com;dashboard:dashboard") I want to show

Dynamic Route Loading in Angular 2 Fails. (Beta)

点点圈 提交于 2019-12-01 01:16:52
I want to load routes for the @RouteConfig Dynamically from a service which fetches in format JSON, [ { "path" : "/about" , "name" : "About" , "component" : "AboutComponent" }, { "path" : "/contact" , "name" : "Contact" , "component" : "ContactComponent" } ] Following is the code for pushing it into the RouteDefinition Array, for (let i = 0; i < data.length; i++) { //console.log(data[i].path+" "+data[i].name+" "+data[i].component); this.routeConfigArray.push({ //routeConfigArray : RouteDefinition 'path': data[i].path, 'name': data[i].name, 'component': data[i].component }); this._router.config

End interval when route changes in Angular 2

本秂侑毒 提交于 2019-11-30 20:19:56
I start a timer in an Angular 2 component which is inside a router outlet. setInterval(() => { ... }, 10000); When I leave the route in which the component is embedded the timer isn't quit. How can I achieve that? This should do it: routerOnActivate() { this.timer = setInterval(()=>{ ... }, 10000); } routerOnDeactivate() { clearInterval(this.timer); } You could clear the interval from this hook. Mine is controlled from the component/view. export classTestInterval implements OnInit, OnDestroy{ public timerInterval:any; ngOnInit(){ // Need interval scope in the component could be from somewhere