rxjs - Angular 2 http GET method calling twice -
this question asked here still not able find answer in , believe have done research ,
a. things have done far:
i have tried .share link same
i have tried check whether preflight reuest , found in network tab:
there 2 option call , 2 call going . so, can sure not preflight request.
now comming towards coding part:
component ------------ constructor( private _notificationservice: notificationservice) { this.getnotification(); } getnotification() { this._notificationservice.getnotifications().subscribe(notifications => { this.notificationlist = notifications; }); } service: ------------- constructor(private http: http,private config: configuration) { } getnotifications() { const headers = new headers({ 'c-t-tenant': 'tenant name', 'c-t-apitoken': 'token-name', 'content-type': 'application/json', }); return this.http.get(this.config.notificationapiurl, { headers: headers }) .map((res: response) => res.json()); } i sure api not getting called somewhere else. if stucked in kind of situation please me here.
my backend in spring boot , have implemented cors filter also:
package com.bosch.cb.dashboard.auth; import java.io.ioexception; import javax.servlet.filter; import javax.servlet.filterchain; import javax.servlet.filterconfig; import javax.servlet.servletexception; import javax.servlet.servletrequest; import javax.servlet.servletresponse; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import org.springframework.stereotype.component; @component public class simplecorsfilter implements filter { public simplecorsfilter() { system.out.println("simplecorsfilter init"); } @override public void init(filterconfig filterconfig) throws servletexception { } @override public void dofilter(servletrequest req, servletresponse resp, filterchain chain) throws ioexception, servletexception { httpservletrequest request = (httpservletrequest) req; httpservletresponse response = (httpservletresponse) resp; response.setheader("access-control-allow-origin", "*"); response.setheader("access-control-allow-credentials", "true"); response.setheader("access-control-allow-methods", "post, get, options, delete"); response.setheader("access-control-max-age", "3600"); response.setheader("access-control-allow-headers", "access-control-allow-headers, pragma, origin,accept, b-h-apitoken ,x-requested-with, content-type, access-control-request-method, access-control-request-headers, authorization"); chain.dofilter(request, response); } @override public void destroy() { } }
try
constructor( private _notificationservice: notificationservice) { this.getnotification().subscribe(notifications => { this.notificationlist = notifications; }); } getnotification() { return this._notificationservice.getnotifications(); } or workaround of
constructor( private _notificationservice: notificationservice) { this.getnotification() .first() .subscribe(notifications => { this.notificationlist = notifications; }); } getnotification() { return this._notificationservice.getnotifications(); } 
Comments
Post a Comment