angular2-services

Access EventEmitter Service inside of CustomHttp

廉价感情. 提交于 2019-12-11 12:14:22
问题 I have created custom interceptor for all Http requests: import {EventEmitterService} from "./EventEmitter.service"; @Injectable() export class CustomHttp extends Http { constructor(backend: ConnectionBackend, defaultOptions: RequestOptions, _eventEmitterService:EventEmitterService) { super(backend, defaultOptions); } get(url: string, options?: RequestOptionsArgs): Observable<Response> { return super.get(url,{headers: interceptorHeaders}).catch((res)=>{ if (res.status === 403){ console.log(

Reset ngModel values on ngIf in angular2

*爱你&永不变心* 提交于 2019-12-11 08:08:06
问题 I have a model which is an array element. I want to clear the values of each element on ngIf condition.Please find below HTML : <div *ngIf="flag" > <table id="table" class="table table-hover table-bordered table-mc-light-blue"> <thead> <tr> <th>col 1</th> <th>col 2</th> </tr> </thead> <tr *ngFor="let item of collection;"> <td>{{item.col1}}</td> <td> <input type="text" class="form-control" [(ngModel)]="item.col2" #input="ngModel" name="input-{{i}}"> </td> </tr> </table> </div> On flag set to

angular 2 service is not updating params

旧时模样 提交于 2019-12-11 08:07:36
问题 I have two components, one with a list of restaurants and another with the menu of the selected restaurant, to get the menu I use this service: import { Injectable } from '@angular/core'; import { Http, Response } from '@angular/http' import {Observable} from 'rxjs/Rx' import 'rxjs/add/operator/map' import { RESTAURANT_MENU } from '../../_helpers/' @Injectable() export class RestaurantsService { private menuUrl = RESTAURANT_MENU constructor(private http: Http) { } getRestaurantMenu

How to parse this json structure in listview angular2 nativescript

怎甘沉沦 提交于 2019-12-11 08:06:22
问题 json structure : { "Employee": [ {"id":1,"name":"Dan" }, {"id":2,"name":"Stack" }, ..... ] } app.component.ts: ngOnInit() { console.log("first", "Test"); this.globalReader.getObjectData() .subscribe(data => this.getData = JSON.stringify(data), ---> Response printed successfully here.I'm able to print it in label. error => alert(error), () => console.log("finished") ); } Edit: component: <label text ="{{getData }}" ></label> getObjectData() { return this._http.get('/page/emp.json') .map(

angular2 in-memory-web-api only for a part of an application

自闭症网瘾萝莉.ら 提交于 2019-12-11 06:04:37
问题 I was wondering if is possible to configure angular2 in-memory-web-api only for a part of an application. I want to reach external endpoints for finished components and use in-memory-web-api for components in development stage. I've tried to do this in the folowing two ways: 1 - Loading the data in the main and changing the XHRBackend in the components that I want to reach in-memory endpoints; main.ts bootstrap(AppComponent, [ ... { provide: SEED_DATA, useClass: InMemoryDataService } ]);

Angular2 this is null in component

情到浓时终转凉″ 提交于 2019-12-11 06:02:40
问题 I'm expecting some weird situations where "this" is null inside a component. SO far, I saw it in two situations: 1) When the promise is rejected: if (this.valForm.valid) { this.userService.login(value).then(result => { if(result.success){ this.toasterService.pop("success", "Exito", "Inicio de session correcto"); this.sessionService.setUser(result.data); this.router.navigateByUrl('home'); } else{ this.error = result.code; } },function(error){ console.log("ERROR: " + error); this.error = "ERROR

Angular 2 Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header

时光总嘲笑我的痴心妄想 提交于 2019-12-11 04:47:17
问题 I'm new to Angular2. And I'm trying to call POST method to my .net core API.It's working fine with Postman.But when I call it from my angular 2 service it gives an error. This is my api.service.ts import { Injectable } from '@angular/core'; import { environment } from '../../../environments/environment'; import { Headers, Http, Response, URLSearchParams } from '@angular/http'; import { Observable } from 'rxjs/Rx'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/catch'; import {

Set Headers using append or set does not work in Angular 2

六月ゝ 毕业季﹏ 提交于 2019-12-11 04:26:44
问题 I am using Angular 2.4.8. I want to append custom headers to each request. I am using BaseRequestOptions to define custom headers and adding it to app providers. Following is the code. import { BaseRequestOptions, Headers } from '@angular/http'; import { Injectable } from '@angular/core'; @Injectable() export class AppBaseRequestOptions extends BaseRequestOptions { public merge(headers: Headers) { headers.append('Content-type', 'application/json'); headers.append('My-Custom-Header', 'My

How to watch from directive on a simple variable changes inside a service?

∥☆過路亽.° 提交于 2019-12-11 01:49:45
问题 I have a simple service with data variable: import { Injectable } from '@angular/core'; @Injectable() export class MyService { private _data:number; get data(): number { return this._data; } set data(value: number) { this._data = value; } } Now from a directive I would like to catch whenever someone is doing set to my variable: this.myService.data = 12345; I was trying to do that with subscribe but missing something on syntax: this.myService.data.subscribe(res => console.log(res)); What am I

ng2 Get Object from HttpGet Service

巧了我就是萌 提交于 2019-12-11 01:35:14
问题 I am trying to get JSON data from my WebAPI and it's not working. I always get undefined whenever I try to use that return object in my component. I would like to display the student and course data on the home landing page of my website. At the moment, my controller / api is returning the hardcoded data. student.service.ts import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import { Http } from '@angular/http'; import 'rxjs/add/operator/map'; import