angular2-services

Dynamic component loader - shared service for the resolving components

*爱你&永不变心* 提交于 2019-12-08 10:11:53
问题 I have to use ComponentFactoryResolver to add components dynamically. For my example, I have a modal window which I dynamically loaded after pressing some button on the view. And code for this action like this: let componentFactory = this.componentFactoryResolver.resolveComponentFactory(XYZComponent); let viewContainerRef = this.containerHost.viewContainerRef; viewContainerRef.clear(); let componentRef = viewContainerRef.createComponent(componentFactory); let _XYZComponent = componentRef

Angular2: How to inject two instances of the same service into multiple components?

风格不统一 提交于 2019-12-08 09:34:59
问题 Suppose that I have an Angular Service that looks like this: @Injectable() export class Clipboard { constructor(private multiple: Multiple, private di:DI, private injected:Injected, private things: Things){} // The clipboard has local state: private isCut: boolean; private toPaste: Hero; cut(hero: Hero){ this.isCut = true; this.toPaste = hero; } copy(hero: Hero){ this.isCut = false; this.toPaste = hero; } paste(locaction: Location){ // Lots of really complex logic } canPaste(potentialLocation

Angular 2 AoT Heep Errors

人盡茶涼 提交于 2019-12-08 05:59:44
问题 AoT compilation resulting in " JavaScript heap out of memory" error I am trying to compile my project by following the AoT guide available on angular.io Below is my typesccript configuration file for aot { "compilerOptions": { "emitDecoratorMetadata": true, "experimentalDecorators": true, "module": "es2015", "moduleResolution": "node", "noImplicitAny": false, "suppressImplicitAnyIndexErrors": true, "noEmitOnError": true, "removeComments": true, "sourceMap": false, "target": "es5", "outDir": "

passing one component data to other component

人盡茶涼 提交于 2019-12-08 05:19:03
问题 I am getting response from server,I want pass this response to other component for displaying. I tried in one way but getting undefined. Tried this way how to pass one component service response to other component in angular 2. yesterday got the results faced routing. Changed little bit created separated components. mainsearch.component.ts: export class MainsearchComponent { selected; skipCount: number = 0; errorMessage: string; searchedResults: any; searchObj: Object = { skipCount: this

Angular2 ExpressionChangedAfterItHasBeenCheckedError

蹲街弑〆低调 提交于 2019-12-08 04:50:18
问题 I've read the documentation on this error, and I think I understand why the issue arises. I'm having a problem trying to figure out an alternative architecture that would suit me. The root component of my site (app.component) has a "loading" component on it. It's a third party component (ngx-loading) that basically throws up a loading indicator to show the user that something is happening in the app that will take a little time. The loading component takes a parameter that tells it whether to

Angular2 App Routing through Services

…衆ロ難τιáo~ 提交于 2019-12-07 19:16:06
问题 Here's my scenario : Il get straight to the point first... I want to load all the routes including the default route of a app in RouteConfig through a service. I am able to do so but cannot load the default route dynamically, other routes can be loaded dynamically. Suppose i bootstrap(AppComponent) and my AppComponent view only content is <router-outlet></router-outlet> so in this scenario the AppComponent RouteConfig needs to be loaded dynamically i.e in my case i call a service which

Angular 2 lazy loaded module - service not singleton

孤街浪徒 提交于 2019-12-07 17:04:28
问题 I have implemented lazy loading modules into my application, the app.module.ts is configured correctly. @NgModule({ declarations: [ AppComponent, HeaderComponent, HomeComponent ], imports: [ BrowserModule, FormsModule, HttpModule, routing ], bootstrap: [AppComponent] }) export class AppModule { } The routing configuration const APP_ROUTES: Routes = [ { path: '', component: HomeComponent }, { path: 'tools', loadChildren: 'app/tools/tools.module#ToolsModule' } ]; export const routing =

Angular 2 RC 5 Bootstrap custom HTTP class

泄露秘密 提交于 2019-12-07 16:32:57
问题 In Angular 2 RC 4 I have a class HttpLoading which extends the original Http of Angular2 I was able to use that in bootstrap without any issue using the below code: bootstrap(AppComponent, [ HTTP_PROVIDERS, provide(RequestOptions, { useClass: DefaultRequestOptions }), provide(Http, { useFactory: (backend: XHRBackend, defaultOptions: RequestOptions) => new HttpLoading(backend, defaultOptions), deps: [XHRBackend, RequestOptions] }) ]).catch(err => console.error(err)); My DefaultRequest Options

Browser Close Event in angular4

自古美人都是妖i 提交于 2019-12-07 16:23:41
问题 How can i detect browser close event in angular 4.0.2 I have tried @HostListener('window:unload', ['$event']) unloadHandler(event) { ... } @HostListener('window:beforeunload', ['$event']) beforeunloadHandler(event) { ... } But not properly working for me. Can anyone help me out. If i refresh page than also this event fires Need Separate browser close event in angular2/4 回答1: You need to set $event.returnValue if you want close event popup Inside component @HostListener('window:beforeunload',

angular 2 update app component from router outlet component

自作多情 提交于 2019-12-07 04:46:20
问题 I'm using angular 2 rc1 and the new router @angular/router In app component I have a nav section and router outlet <nav> <a *ngIf="auth?.userName == null" [routerLink]="['/login']">Login</a> <a *ngIf="auth?.userName != null" (click)="logout()">Logout</a> {{auth?.userName}} </nav> <router-outlet></router-outlet> I inject a loginService into app component and subscribe to an event in ngOnInit ngOnInit() { this.loginService.loginSuccess.subscribe(this.loginSuccess); } ngOnDestroy() { this