angular2-routing

Angular 2 get routeParams in a service

冷暖自知 提交于 2019-12-09 17:37:10
问题 I want to shift the logic from component to service. But I found out that I can't get the routeParams in a service. My component looks like import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Params } from '@angular/router'; import { MyService } from '../services/my.service'; @Component({ moduleId: module.id, templateUrl: 'my.component.html', styleUrls: ['my.component.css'] }) export class MyComponent implements OnInit { constructor(private myService: MyService,

Angular 2 app base href with Cordova IOS

旧巷老猫 提交于 2019-12-09 16:50:34
问题 I am developing an application using Angular 2 with cordova. I have used the angular cli to build the appplication. I have now ran into some routing issues on startup when it comes to the IOS application. The base href seems to be set wrong. If I set the base href using: <base href="/" target="_blank"> the application doesn't load. If the base href is set when I bootstrap the application using: ...,provide(APP_BASE_HREF, {useValue:'/'}), ... the application will load but I get the following

Angular 2 New Router: Change / Set Query Params

℡╲_俬逩灬. 提交于 2019-12-09 15:39:39
问题 I have a component registered at /contacts , which displays a list of contacts. I've added an <input [value]="searchString"> for filtering the displayed list. Now I'd like to display the searchString within the URL in form of a Query Param. (Using the New Router 3.0.0 RC2) The official docs ( https://angular.io/docs/ts/latest/guide/router.html#!#query-parameters ) show how to use router.navigate for changing the queryParams . But this seems awkward, because I just want to change the

Passing dynamic data through Angular 2 route

和自甴很熟 提交于 2019-12-09 15:08:38
问题 It is possible to pass static data to an Angular 2 route without showing it on the URL. But how can I pass dynamic data/object in the same way? 回答1: You can use a resolver. The data returned by a resolver is made available to routes the same way static data on route configurations is For an example see https://angular.io/guide/router#resolve-guard @Injectable() export class CrisisDetailResolve implements Resolve<Crisis> { constructor(private cs: CrisisService, private router: Router) {}

Angular2: unable to navigate to url using location.go(url)

╄→尐↘猪︶ㄣ 提交于 2019-12-09 07:59:25
问题 I am trying to navigate to a specific url using location.go service from typescript function. It changes the url in the browser but the component of the url is not reflected in the screen. It stays on the login (actual) screen - say for eg: constructor(location: Location, public _userdetails: userdetails){ this.location = location; } login(){ if (this.username && this.password){ this._userdetails.username = this.username; this.location.go('/home'); } else{ console.log('Cannot be blank'); } }

404 Error on refresh for angular(v4+) deployed on tomcat server

自闭症网瘾萝莉.ら 提交于 2019-12-09 05:37:45
问题 I have deployed an angular application with lazy loading. The application works perfectly when hosted on Github.io domain but I am getting an error when I deployed the app on tomcat server using mobaxterm. When the page reloads or refreshes the app loses the routing state and throws a 404 error. HTTP Status 404 - /enquiry type Status report message /enquiry description The requested resource is not available. Apache Tomcat/7.0.72 Console-Log:: GET http://appv2.proctur.com/enquiry/addEnquiry

Passing data from child to parent component ( child loaded via routing)

北城余情 提交于 2019-12-09 03:39:28
问题 I have this issue. Chat is a parent component and it has Messages child component. I have url-s, /chat/ , /chat/:id . So i can get :id param in Messages component with RouteParams , but i need that :id in Chat component. So if i load /chat/46 then Chat component knows that 46 :id If i am loading it as directive something like <messages (Event)="handleEvent()"></messages> than i can pass it via EventEmitter and Output, but if i load component through <router-outlet> how i can pass value back

Cannot match any routes

…衆ロ難τιáo~ 提交于 2019-12-09 02:14:33
问题 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 when navigating programatically, old component stays in the dom

瘦欲@ 提交于 2019-12-08 20:57:52
问题 Angular version: 4 After signing in from the LoginComponent (located in public/signin route, I want to navigate to TestComponent in the path public/test . I'm doing so as following: this._router.navigate(['public/test']) Then, it redirects correctly but the problem is that it doesn't remove LoginComponent from the DOM (although ngOnDestroy does get called). It's worth mentioning that navigating to TestComonent using <a routerLink='/public/test'>Test</a> works as expected. What am I doing

Angular 2 Uncaught (in promise): TypeError: Cannot read property 'isActivated' of undefined

心不动则不痛 提交于 2019-12-08 15:44:14
问题 If I return to the same routing path it show an error "Uncaught (in promise): TypeError: Cannot read property 'isActivated' of undefined". But not show at first time. can any one help me ? routing const mainRoutes: Routes = [ { path: '', pathMatch: 'full', redirectTo: '/home' }, { path: 'home', loadChildren: './apps/home/home.module#HomeModule', canActivate: [AuthGuard], resolve: { crisis: NavigarionResolve } } { path: '**', component: PageNotFoundComponent } ]; Component import { Component,