angular4-router

How to handle data comes late from service?

家住魔仙堡 提交于 2019-12-24 00:24:40
问题 In my angular application, i am in the need to store the data to an array which will be empty at initial stage. Example : someFunction() { let array = []; console.log("step 1"); this.service.getRest(url).subscribe(result => { result.data.forEach(element => { console.log("step 2"); array.push(element); // Pushing all the objects comes from res.data }); console.log("step 3"); }); console.log("step 4"); } Here i have listed down the console.log() with step order. In which the order while calling

Angular 2/4/5 - Load child component to main router-outlet

时光毁灭记忆、已成空白 提交于 2019-12-23 02:21:39
问题 I am working with angular 5 currently. I have came across the problem with my router configuration and its presentation of component content accordingly. As below is my router configuration. const appRoutes: Routes = [ { path: "", pathMatch: "full", redirectTo: "home" }, { path: "home", component: HomeComponent }, { path: "applications", component: ApplicationsComponent, children: [{ path: ":applicationId/privacysettingsforapplications", component: PrivacysettingsforapplicationsComponent,

how to alert user on click of browser back button in angular 4?

无人久伴 提交于 2019-12-22 18:46:38
问题 how to alert the user on click of browser back button in angular 4? onpopstate gets called even when the page loads for the first time import { PlatformLocation } from '@angular/common'; constructor( private platformLocation: PlatformLocation) { platformLocation.onPopState(() => { console.log("onPopState called"); window.alert("your data will be lost"); }) } 回答1: Add a candeactivate guard can-deactivate-guard.service.ts import {Observable} from 'rxjs'; import {CanDeactivate,

angular 4 router without router-outlet

 ̄綄美尐妖づ 提交于 2019-12-21 17:39:33
问题 I am currently implementing a custom state management in angular 4 based on angular router, basically without any router-outlet attaching and detaching components myself based on routing events. It works fine until i try to navigate from a route with parameters to the same route with different parameters, then it crashes. This plunkr ( watch the console ) explains my situation. Navigating from ' crisis center ' to ' heroes ' is fine, navigating from ' heroes ' to ' hero 11 ' is fine,

How to route in angular 4

…衆ロ難τιáo~ 提交于 2019-12-21 04:07:16
问题 I have an angular 4 project and when I run it from localhost:4200/route-a , it works fine and when I refresh the browser, all works well as expected. However, when I build it with ng build and run it from apache, navigating to localhost/route-a returns a 404 . Here is my code for routing: imports: [BrowserModule, HttpModule, FormsModule, RouterModule.forRoot([ { path: 'home', component: HomeComponent }, { path: 'route-a', component: RouteAComponent }, { path: '', redirectTo: '/home',

Read route params from directly entered url in app

有些话、适合烂在心里 提交于 2019-12-20 06:30:47
问题 My question would be regarding angular 4, how to get route params, if for example a user gets on your page with, instead of the default url, like for example http://localhost:3000/ , to something like http://localhost:3000/user/:id , and to be able to pick up the :id from that url (user has directly entered it in the browser, not navigating through the app). In the example bellow same component is used, mainly because of needing to catch that id and dispatch other actions, if its present, and

Angular 4 router: prevent direct browser navigation

梦想的初衷 提交于 2019-12-12 08:44:22
问题 How can I convince the Angular 4 router to disable direct browser navigation within my app? I have looked into the router hooks CanActivate and CanDeactivate and implemented them but CanDeactivate does not fire at all when using direct browser navigation. I can use CanActivate to prevent the url but only after the app reboots, which takes time and undesired changes in the browser window. I want to be able to catch the direct browser navigation BEFORE the app reboots. In case this helps: I

How to pass the value and get the value from another page via routerlink in angular4?

依然范特西╮ 提交于 2019-12-11 20:08:44
问题 I want to pass a value with URL using routerLink and read that value on another page. Like I have Modules and Submodules. On select of first record the id of that record pass to User page. After read that Userid I want to show detail of that User and modules/submodules. So How can I pass and get the Values(object)? Userdetails Component class: import { Component, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; @Component({ selector: 'userdetail', templateUrl:

angular4 route issue by adding '%2f' character before path

萝らか妹 提交于 2019-12-11 05:47:55
问题 reason of using nested route for me is handling dynamically icon and back button for every page.i have abstract route because when i click to back button route params disappear and i put an abstract path to keep id and questionnaire type parameter in url.my abstract path is Questionaire { path: 'Home', component: HomeComponent,data:{icon:'fa-home'} }, { path: 'QuestionaireList', component: QuestionaireListComponent,data:{icon:'fa-list-ul',previousState:'/Home'} }, { path: 'Questionaire/

Angular: two different modules or single module

ε祈祈猫儿з 提交于 2019-12-11 04:14:21
问题 I recently started working on Angular ( Angular5 ). My application has tabs named Home, School, Office and I have two types of users Admin and non-admin . As soon as the Office tab is clicked Admin page will be redirected to Admin page and non-admin user will be redirected to non-admin page. So, for this requirement do I need to make two different modules? OR shall I make a single module and redirect on the bases of user types? Please guide me with the project structure. 回答1: Yes, you need to