angular2-routing

EmptyError: no elements in sequence

纵饮孤独 提交于 2019-11-27 03:02:59
问题 I'm upgrading my Angular2 app from 2.0.0 to 2.3.0, and I'm running into the following error. Any ideas as to why? I saw this other post (Angular 2.0.1 Router EmptyError: no elements in sequence), but after trying this, the issue still remains. What causes this error? Error: Uncaught (in promise): EmptyError: no elements in sequence Error: no elements in sequence at EmptyError.ZoneAwareError (zone.js:672) at new EmptyError (EmptyError.ts:13) at FirstSubscriber._complete (first.ts:161) at

Angular2. How to hide(no-render) the link in the menu after check access?

百般思念 提交于 2019-11-27 02:26:30
问题 Need to hide link in menu based on the "routerLink" after check ACL access. I do not want to use angular directives "*ngIf" on each element link in app (need to do that globaly on the routerConfig definition) Content can controll using annotation @CanActivate on components but need to hide link in menu I try do that with overwrite "routerLink" directive, but in this directives after overwrite can't get access to my extends param defined(resources and privilages) in routerConfig Example:

Custom encoding for urls using Angular 2 Router (using a + sign in place of a space)

萝らか妹 提交于 2019-11-27 02:19:30
问题 I am using an Angular 2 Router to update the query params in a URL for a search application. I am attempting to replace spaces in a query with + signs. However, + signs are getting encoded. For example: this.router.navigatebyUrl('?q=one+two'); populates the URL with "?q=one%2Btwo". In looking at the source code for Angular 2, it looks like the router converts the URL to a UrlTree which uses encodeURIComponent() to encode the url. Because of this, it is impossible to prevent the default

Handling 404 with Angular2

北城余情 提交于 2019-11-27 02:11:28
问题 Is there any way to configure Angular2 router to redirect to specific route, if invalid path is entered? For example if I have three routes: /home /about /404 and I enter /trains (a route, not present in route config), I'd like the router to redirect me to 404. 回答1: Update for new @angular/router The new router handles missing routes much nicer with the '**' path specification. In your root RouterConfig , adding a component as a catch-all will catch incorrect routes at the root level and

Angular 2 passing object via route params possible?

元气小坏坏 提交于 2019-11-27 02:07:48
I could use some advice how to approach this problem I'm facing. To explain this best possible for you I have created a main component: @Component({ selector: 'main-component', providers: [...FORM_PROVIDERS, MainService, MainQuoteComponent], directives: [...ROUTER_DIRECTIVES, CORE_DIRECTIVES, RouterOutlet, MainQuoteComponent ], styles: [` agent { display: block; } `], pipes: [], template: ` **Html hidden** `, bindings: [MainService], }) @RouteConfig([ { path: '/', name: 'Main', component: MainMenuComponent, useAsDefault: true }, { path: '/passenger', name: 'Passenger', component:

Angular 2 Authentication with child routes

╄→гoц情女王★ 提交于 2019-11-27 01:58:49
问题 I have an angular 2 application in which I need to be authenticated on every page. So I have implemented a custom RouterOutlet to confirm I am logged in on every page change. @Directive({ selector: 'auth-outlet' }) export class AuthOutlet extends RouterOutlet { publicRoutes: any; private parentRouter: Router; private authService: AuthService; constructor(_elementRef: ElementRef, _loader: DynamicComponentLoader, _parentRouter: Router, @Attribute('name') nameAttr: string, _authService:

Angular2 router.navigate refresh page

余生长醉 提交于 2019-11-27 01:57:00
This is how the routes and component look like: routes.config export const routes: RouterConfig = [ { path: 'users', component: UsersComponent, canActivate: [AuthGuard] }, { path: 'users/new', component: NewUserComponent }, ]; new-user.component addField(newName: string){ this.items.push({ name: newName, }) this._router.navigate(['/users']) Is Angular2 supposed to refresh the page on router.navigate? What else to use instead of router.navigate to avoid any page refresh? Here is the proof: ElSnakeO You are probably calling the router.navigate function inside a click event. <button class="btn

How can I access an activated child route's data from the parent route's component?

亡梦爱人 提交于 2019-11-27 01:39:36
问题 const appRoutes: Routes = [ { path: 'parent', component: parentComp, data: { foo: 'parent data' }, children: [ { path: 'child1', component: childComp1, data: { bar: 'child data 1' }, { path: 'child2', component: childComp2, data: { bar: 'child data 2' } ]} ]; If I navigate to /parent/child2 and then look at the ActivatedRoute from parentComp , data.foo is defined, but data.bar is not. I have access to an array of all the children, but I don't know which one is activated. How can I access the

ASP.NET 5 + Angular 2 routing (template page not REloading)

随声附和 提交于 2019-11-27 01:18:56
问题 Angular 2 beta uses html5 routing by default. However, when you go to a component and the route changes (eg http://localhost:5000/aboutus) and you reload/refresh the page, nothing is loaded. The issue has been raised in this post also. Most of the answers say that if we are going to pursue HTML5 routing in angular 2, then this issue of routing should be taken care of in server-side. More discussion here . I am not sure how to handle this issue using the asp.net server environment. Any angular

How to send a value from one component to another?

て烟熏妆下的殇ゞ 提交于 2019-11-27 01:12:18
问题 I make a componenet in which I have one input field and button.On click of button I am diplaying the second component.I want to send data from one component to another component ? how I will send data from one component to another ..I need to send input value (what ever user type in input field ) I need to show on next component or next page .On button click .how to send data ? here is my plunker http://plnkr.co/edit/IINX8Zq8J2LUTIyf4DYD?p=preview import {Component,View} from 'angular2/core';