Common Service for multiple module
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
Can someone help me out fixing this issue?
I have a service which has multiple methods each method perform some task after receiving the response from the server and then I have to pass the modified response to the respective caller component.
this is the code I have in the service.
getData(observer){
// prepare request Object
this.httpService.getDropdownData(reqObj).subscribe(
(data) => {
// modify response and then pass it to the respective component.
//I can't think of any solution from here. tried adding
observable but not getting the desired output(scoping issue)
observer.next(data);
observer.complete();
}, (error) => {
// error case
});
}
public observeData = new Observable(getData);
// component code.
this.cmpService.observeData().subscribe( response){
do something with the response.
};
expecting a modified output in each component.
angular rxjs observable
add a comment |
Can someone help me out fixing this issue?
I have a service which has multiple methods each method perform some task after receiving the response from the server and then I have to pass the modified response to the respective caller component.
this is the code I have in the service.
getData(observer){
// prepare request Object
this.httpService.getDropdownData(reqObj).subscribe(
(data) => {
// modify response and then pass it to the respective component.
//I can't think of any solution from here. tried adding
observable but not getting the desired output(scoping issue)
observer.next(data);
observer.complete();
}, (error) => {
// error case
});
}
public observeData = new Observable(getData);
// component code.
this.cmpService.observeData().subscribe( response){
do something with the response.
};
expecting a modified output in each component.
angular rxjs observable
Please post all the code for your service(s) and your component.
– Andrew Felder
Jan 4 at 13:44
add a comment |
Can someone help me out fixing this issue?
I have a service which has multiple methods each method perform some task after receiving the response from the server and then I have to pass the modified response to the respective caller component.
this is the code I have in the service.
getData(observer){
// prepare request Object
this.httpService.getDropdownData(reqObj).subscribe(
(data) => {
// modify response and then pass it to the respective component.
//I can't think of any solution from here. tried adding
observable but not getting the desired output(scoping issue)
observer.next(data);
observer.complete();
}, (error) => {
// error case
});
}
public observeData = new Observable(getData);
// component code.
this.cmpService.observeData().subscribe( response){
do something with the response.
};
expecting a modified output in each component.
angular rxjs observable
Can someone help me out fixing this issue?
I have a service which has multiple methods each method perform some task after receiving the response from the server and then I have to pass the modified response to the respective caller component.
this is the code I have in the service.
getData(observer){
// prepare request Object
this.httpService.getDropdownData(reqObj).subscribe(
(data) => {
// modify response and then pass it to the respective component.
//I can't think of any solution from here. tried adding
observable but not getting the desired output(scoping issue)
observer.next(data);
observer.complete();
}, (error) => {
// error case
});
}
public observeData = new Observable(getData);
// component code.
this.cmpService.observeData().subscribe( response){
do something with the response.
};
expecting a modified output in each component.
angular rxjs observable
angular rxjs observable
asked Jan 4 at 13:28
NitinNitin
115
115
Please post all the code for your service(s) and your component.
– Andrew Felder
Jan 4 at 13:44
add a comment |
Please post all the code for your service(s) and your component.
– Andrew Felder
Jan 4 at 13:44
Please post all the code for your service(s) and your component.
– Andrew Felder
Jan 4 at 13:44
Please post all the code for your service(s) and your component.
– Andrew Felder
Jan 4 at 13:44
add a comment |
2 Answers
2
active
oldest
votes
It should better be something like:
service:
getData(): Observable<any> {
return this.httpService.getDropdownData(reqObj).pipe(
// do your stuffs here with the help of rxjs operators
);
}
component:
this.cmpService.getData().subscribe(
data => console.log(data), // here you'll get modified datas
err => console.log(err), // here, you'll manage errors in your component
() => {}
);
Hope it helps ;-)
1
let me try this. thanks
– Nitin
Jan 4 at 17:06
add a comment |
this is what I have tried and able to achieve my goal but not sure what performance impact it has and if this is the correct way of using observable?
getCmpData(): Observable<any>{
this.spinner.show();
let userGroups =
if(userData != null){
userData = JSON.parse(userData);
if(userData.user && userData.user.userGroups &&
userData.user.userGroups.length){
userGroups = userData.user.userGroups;
}
}
return Observable.create(observer => {
this.httpService.getData('cmpInfo/', userGroups)
//.map(res => res.json())getting ts error so commented out
.subscribe((data) => {
if (data[0].status != 'ERROR') {
observer.next(data[0].results);// each component has different logic to use this data.
observer.complete();
}else{
this.spinner.hide();
this.modalService.showErrorMessage();
observer.unsubscribe();
}
}, (error) => {
this.spinner.hide();
this.modalService.showErrorMessage();
observer.unsubscribe();
});
});
}
}
//component code.
this.cmpService.getCmpData().subscribe(
(data) => {
// further logic
});
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54039877%2fcommon-service-for-multiple-module%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
It should better be something like:
service:
getData(): Observable<any> {
return this.httpService.getDropdownData(reqObj).pipe(
// do your stuffs here with the help of rxjs operators
);
}
component:
this.cmpService.getData().subscribe(
data => console.log(data), // here you'll get modified datas
err => console.log(err), // here, you'll manage errors in your component
() => {}
);
Hope it helps ;-)
1
let me try this. thanks
– Nitin
Jan 4 at 17:06
add a comment |
It should better be something like:
service:
getData(): Observable<any> {
return this.httpService.getDropdownData(reqObj).pipe(
// do your stuffs here with the help of rxjs operators
);
}
component:
this.cmpService.getData().subscribe(
data => console.log(data), // here you'll get modified datas
err => console.log(err), // here, you'll manage errors in your component
() => {}
);
Hope it helps ;-)
1
let me try this. thanks
– Nitin
Jan 4 at 17:06
add a comment |
It should better be something like:
service:
getData(): Observable<any> {
return this.httpService.getDropdownData(reqObj).pipe(
// do your stuffs here with the help of rxjs operators
);
}
component:
this.cmpService.getData().subscribe(
data => console.log(data), // here you'll get modified datas
err => console.log(err), // here, you'll manage errors in your component
() => {}
);
Hope it helps ;-)
It should better be something like:
service:
getData(): Observable<any> {
return this.httpService.getDropdownData(reqObj).pipe(
// do your stuffs here with the help of rxjs operators
);
}
component:
this.cmpService.getData().subscribe(
data => console.log(data), // here you'll get modified datas
err => console.log(err), // here, you'll manage errors in your component
() => {}
);
Hope it helps ;-)
answered Jan 4 at 14:18
dun32dun32
47535
47535
1
let me try this. thanks
– Nitin
Jan 4 at 17:06
add a comment |
1
let me try this. thanks
– Nitin
Jan 4 at 17:06
1
1
let me try this. thanks
– Nitin
Jan 4 at 17:06
let me try this. thanks
– Nitin
Jan 4 at 17:06
add a comment |
this is what I have tried and able to achieve my goal but not sure what performance impact it has and if this is the correct way of using observable?
getCmpData(): Observable<any>{
this.spinner.show();
let userGroups =
if(userData != null){
userData = JSON.parse(userData);
if(userData.user && userData.user.userGroups &&
userData.user.userGroups.length){
userGroups = userData.user.userGroups;
}
}
return Observable.create(observer => {
this.httpService.getData('cmpInfo/', userGroups)
//.map(res => res.json())getting ts error so commented out
.subscribe((data) => {
if (data[0].status != 'ERROR') {
observer.next(data[0].results);// each component has different logic to use this data.
observer.complete();
}else{
this.spinner.hide();
this.modalService.showErrorMessage();
observer.unsubscribe();
}
}, (error) => {
this.spinner.hide();
this.modalService.showErrorMessage();
observer.unsubscribe();
});
});
}
}
//component code.
this.cmpService.getCmpData().subscribe(
(data) => {
// further logic
});
add a comment |
this is what I have tried and able to achieve my goal but not sure what performance impact it has and if this is the correct way of using observable?
getCmpData(): Observable<any>{
this.spinner.show();
let userGroups =
if(userData != null){
userData = JSON.parse(userData);
if(userData.user && userData.user.userGroups &&
userData.user.userGroups.length){
userGroups = userData.user.userGroups;
}
}
return Observable.create(observer => {
this.httpService.getData('cmpInfo/', userGroups)
//.map(res => res.json())getting ts error so commented out
.subscribe((data) => {
if (data[0].status != 'ERROR') {
observer.next(data[0].results);// each component has different logic to use this data.
observer.complete();
}else{
this.spinner.hide();
this.modalService.showErrorMessage();
observer.unsubscribe();
}
}, (error) => {
this.spinner.hide();
this.modalService.showErrorMessage();
observer.unsubscribe();
});
});
}
}
//component code.
this.cmpService.getCmpData().subscribe(
(data) => {
// further logic
});
add a comment |
this is what I have tried and able to achieve my goal but not sure what performance impact it has and if this is the correct way of using observable?
getCmpData(): Observable<any>{
this.spinner.show();
let userGroups =
if(userData != null){
userData = JSON.parse(userData);
if(userData.user && userData.user.userGroups &&
userData.user.userGroups.length){
userGroups = userData.user.userGroups;
}
}
return Observable.create(observer => {
this.httpService.getData('cmpInfo/', userGroups)
//.map(res => res.json())getting ts error so commented out
.subscribe((data) => {
if (data[0].status != 'ERROR') {
observer.next(data[0].results);// each component has different logic to use this data.
observer.complete();
}else{
this.spinner.hide();
this.modalService.showErrorMessage();
observer.unsubscribe();
}
}, (error) => {
this.spinner.hide();
this.modalService.showErrorMessage();
observer.unsubscribe();
});
});
}
}
//component code.
this.cmpService.getCmpData().subscribe(
(data) => {
// further logic
});
this is what I have tried and able to achieve my goal but not sure what performance impact it has and if this is the correct way of using observable?
getCmpData(): Observable<any>{
this.spinner.show();
let userGroups =
if(userData != null){
userData = JSON.parse(userData);
if(userData.user && userData.user.userGroups &&
userData.user.userGroups.length){
userGroups = userData.user.userGroups;
}
}
return Observable.create(observer => {
this.httpService.getData('cmpInfo/', userGroups)
//.map(res => res.json())getting ts error so commented out
.subscribe((data) => {
if (data[0].status != 'ERROR') {
observer.next(data[0].results);// each component has different logic to use this data.
observer.complete();
}else{
this.spinner.hide();
this.modalService.showErrorMessage();
observer.unsubscribe();
}
}, (error) => {
this.spinner.hide();
this.modalService.showErrorMessage();
observer.unsubscribe();
});
});
}
}
//component code.
this.cmpService.getCmpData().subscribe(
(data) => {
// further logic
});
answered Jan 6 at 7:37
NitinNitin
115
115
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54039877%2fcommon-service-for-multiple-module%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please post all the code for your service(s) and your component.
– Andrew Felder
Jan 4 at 13:44