angular-router

Angular Service singleton constructor called multiple times

Deadly 提交于 2019-12-05 07:10:43
I am trying to use an app-wide service (UserService) that stores authenticated user details. I have set up some routes but found that UserService is instantiated per route. I want them to share the same UserService. I have created a CoreModule containing TestService as provider and imported it into AppModule. core.module.ts: import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { TestService } from '../test.service'; @NgModule({ imports: [ CommonModule ], declarations: [], providers: [ TestService ] }) export class CoreModule { } test.service.ts:

Act when lazy loaded module is destroyed

ぃ、小莉子 提交于 2019-12-05 01:24:17
问题 I have an Angular 6 application and I am lazy loading a module and passing some data via the router. Once in the module, I call a method within a shared service to which I pass this data (config stuff). I need to call a method when that module is destroyed (essentially, when the user leaves that path), but I want to call it only once, so I want to avoid having to watch the route changing constantly as this will be expensive. The reason is I need to reset the shared service configuration.

Angular 4 animation for fade in and out a view

北城以北 提交于 2019-12-04 18:03:32
I just want the view to fade in and out on route change. I have setup the component correctly it seems but need to get the animation syntax correct I think. This is my current animation attempt. I import this animation to my component: import {trigger, state, animate, style, transition} from '@angular/animations'; export function routerTransition() { return fadeInAndOut(); } function fadeInAndOut() { return trigger('routerTransition', [ transition(':enter', [ style({opacity: 0}), animate(3000, style({opacity: 1})) ]), transition(':leave', [ animate(3000, style({opacity: 0})) ]) ]); } This is

Cannot read property 'outlets' of null in Angular 4

非 Y 不嫁゛ 提交于 2019-12-04 16:02:10
问题 I have Angular 4.3.6 project where a template snippet produces this error. Template block: <a [routerLink]="['/article',article?.id]">{{article?.title}}</a> Error stack trace: ArticleSpComponent.html:26 ERROR TypeError: Cannot read property 'outlets' of null at createNewSegmentGroup (router.es5.js:2967) at updateSegmentGroup (router.es5.js:2896) at router.es5.js:2914 at forEach (router.es5.js:593) at updateSegmentGroupChildren ( The error cause seems to be obvious. article variable is fetched

Angular 4 - Pass an object from one component to another (no parent - child hierarchy)

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 04:51:23
My situation: I have a component showing tiles with each tile representing an object from an array that is looped over with an ngfor. When a tile is clicked I want to pass the object to a different component, which is responsable for displaying all properties of that object in fields that can be modified. What I have tried: After doing some research and coming across multiple posts showing me how to achieve this for a parent - child hierarchy and some posts explaining that it is necessary to use a shared service in order to achieve the wanted funcitonality, I decided to try and setup such a

Angular reuse same lazy load module for multiple root paths

眉间皱痕 提交于 2019-12-04 02:33:28
I've splitted my app into two modules: one with main basic functionality and other with less-used features like account settings, faq pages and more. What I'm trying to accomplish is to lazy load the second module for some root route paths, like /account or /settings without having to create many different modules. As far as I know Angular lazy load only works with one root route, and the routes configured in the lazy loaded module are set as children of that route. { path: 'account', loadChildren: './modules/settings/settings.module#SettingsModule', }, { path: 'settings', loadChildren: '.

Angular 5 Scroll to top on every Route click

喜欢而已 提交于 2019-12-03 18:20:33
问题 I am using angular 5. I have a dashboard where I have few sections with small content and few sections with so large content that I am facing a problem when changing router while going to top. Every time I need to scroll to go to top. Can anyone help me to solve this issue so that when I change the router my view always stay at the top. Thanks in advance. 回答1: A router outlet will emit an activate event any time a new component is being instantiated, so (activate) event could be to scroll

Angular : Error: Uncaught (in promise) at webpackAsyncContext (eval at ./src/$$_lazy_route_resource

人盡茶涼 提交于 2019-12-03 17:56:05
问题 I'm upgrading from Angular 4.0.0 to Angular 5.2.6 i'm facing some problem to get lazy module loading working. with angular 4.0.0 , it works fine , but now , with 5.2.6 , i getting such an error when clicking my redirecting button : core.js:1448 ERROR Error: Uncaught (in promise): TypeError: undefined is not a function TypeError: undefined is not a function at Array.map (<anonymous>) at webpackAsyncContext (eval at ./src/$$_lazy_route_resource lazy recursive (main.bundle.js:27), <anonymous>:13

Dynamically loading an external webpack bundled ngModule as a route handler

余生颓废 提交于 2019-12-03 15:29:40
问题 We want to divide our large frontend projects into multiple separately deployed projects which are easier to work with. I am trying to include a bundled ngModule to handle a route from within another app. The apps must be ignorant of each other's configuration. The bundles will share some large dependencies(like Angular) via globals. We don't need to shake across the bundles and we may just have to accept some duplicate dependencies. The root router complains that Error: No NgModule metadata

Act when lazy loaded module is destroyed

邮差的信 提交于 2019-12-03 15:19:41
I have an Angular 6 application and I am lazy loading a module and passing some data via the router. Once in the module, I call a method within a shared service to which I pass this data (config stuff). I need to call a method when that module is destroyed (essentially, when the user leaves that path), but I want to call it only once, so I want to avoid having to watch the route changing constantly as this will be expensive. The reason is I need to reset the shared service configuration. Basically, I have certain configuration data for the application, and I need to override it for the lazy