angular2-services

Angular2 viewContainerRef.createComponent work correctly

こ雲淡風輕ζ 提交于 2019-12-05 19:40:15
i used viewContainerRef.createComponent to load dynamic component into root component(.....) ,but actual it append the wrong place, my code: -----app.compoment.ts----- export class AppComponent { private viewContainerRef:ViewContainerRef; public constructor(viewContainerRef:ViewContainerRef) { this.viewContainerRef = viewContainerRef; } } -----a.service.ts------ @Injectable() export class ModalService { private viewContainerRef:ViewContainerRef; constructor(applicationRef: ApplicationRef, injector: Injector,private compiler: ComponentResolver) { var classOfRootComponent = applicationRef

Accessing async variable of service

隐身守侯 提交于 2019-12-05 16:11:56
This is part of my first Angular 4 project. I am currently able to call the searchCall function just fine from a search bar, but the data being stored in tweetsData doesn't seem to be in scope with my *ngFor call in app.component.html, as well as being an asynchronous backend call to the twitter api. I get this error: TypeError: Cannot read property 'subscribe' of undefined, so I must not have the observable setup correctly. Any help is greatly appreciated. twitter.service.ts import { Injectable } from '@angular/core'; import { Http, Headers } from '@angular/http'; import { Observable } from

angular 2 update app component from router outlet component

梦想与她 提交于 2019-12-05 10:26:41
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.loginService.loginSuccess.unsubscribe(); } private loginSuccess(res: IAuthResponse) { this.auth = res; } when

Watch for changes in Angular 2 services function

Deadly 提交于 2019-12-05 09:28:38
I have a service named HomeService and in that service I am setting and getting some data which is working fine. Here is the code for my service. import { Injectable } from '@angular/core'; @Injectable() export class HomeService { name:string; constructor() { } setParams(val) { this.name = val; } getParams() { return this.name; } } I am setting params in a component A and getting it in component B . What I want is to keep watching the getParams() for changing in the second component. I am getting the params value in component A in which I am setting it but I couldn't get those value in

Angular2 subscribe inside subscribe

ε祈祈猫儿з 提交于 2019-12-05 03:36:53
In Angular2, what would be the correct way to implement a second API call based on the result from the first API call? One of my Angular2 components has the following method. I tried with having a subscribe inside another subscribe on complete and the response from the second subscribe is always 'undefined'. Edit based on suggestion from CozyAzure. export interface Result { host: string; resourceUri: string; groupId?: string; resource?: any; } private curateResults(searchTerm: string, searchResults: SearchResults): Result[] { const results: Result[] = []; if (searchResults.results !==

Angular2 's Http.post is not returning headers in the response of a POST method invocation

拈花ヽ惹草 提交于 2019-12-05 02:28:31
问题 I am doing a call to a REST endpoint. I want to add a resource (below). However, when my service calls Http's post method it will invoke the request but the response's header(s) are not returned. At least, I experience an empty headers object of the Response instance. (??) I do expect response header. In particular I expect the Location header as part of a "REST ADD RESOURCE" pattern. The Location headers contains the URL of the newly created resource. The weird thing about this: when I call

Access Parent @Component and vars from *Routed* Child Component

我的梦境 提交于 2019-12-05 01:06:52
I am trying to toggle a side nav menu, located at the top of my main App template using a button in a nested child component. I can't figure out how to get to the sidenav component in the parent to tell it to sidenav.open() . I know about @Input and @Output on a child component, but as I understand it, to use this I need to have some sort of DOM tag for the child component to attach these to? Such as: <app> <sidenav-component #sidenav>...</sidenav-component> <child [someInput]="some_parent_var" (childOpensNav)="sidenav.open()"></child> </app> Tons of articles on how to do this. Problem is that

How to change NgModule configuration at runtime

情到浓时终转凉″ 提交于 2019-12-04 22:28:19
问题 There are some modules that expose their service configuration, for example: AngularFireModule.initializeApp(firebaseConfig) , StoreModule.provideStore(reducer) , RouterModule.forRoot(routes) ... How would I reconfigure one of these at runtime? For example, user selects one of two links and different module is lazy loaded and configured differently... How can I pass data to this new NgModule? All I can think of is to put something in global scope and read it from there, but... doesn't feel

Angular 2 Header component Title change dynamically according to the state

与世无争的帅哥 提交于 2019-12-04 22:24:42
问题 I have a design using angular 2 where header component, navigation bar component and body component where all other components load. As the picture shows below Header Navigation Where other components load (this section might have nested components/ children components) So here basically, In the header component, I want to show the current state . And in the bottom of the current state, I want to show the previous state of the user. Issues: To implement this I used the component interaction

How to fix CORS issue http request in Angular 5 [duplicate]

被刻印的时光 ゝ 提交于 2019-12-04 22:04:48
This question already has answers here : How does Access-Control-Allow-Origin header work? (13 answers) Closed 7 months ago . I am new in Angular 5, and I want to send http request but it return CORS error in inspect element. Error XMLHttpRequest cannot load http://example.com/account/create . Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' http://localhost:4200 ' is therefore not allowed access. The response had HTTP status code 403. Below is my code: postFormData(apiUrl: string, value: