I'm trying to separate the http request from my component and putting it in a service, how can I pass the response I get from the request to my action in my component?
Like in angular 1 you can do something like the code below in the controller, and do the http request in a service.
var getGenreList = function() {
coreGenreService.getGenreList(vm.id)
.then(function(response) {
console.log(vm.name);
});
}
I tried sort of applying the same logic however I'm not sure how I can pass the response to my controller.
Service:
getUser(){
this.http.get('http://../api/User?email='+this.customerEmail)
.map(response => response.text())
.subscribe(data => {
if (data) {
var userObj = JSON.parse(data);
this.UserEmail = userObj.EmailAddress;
}
});
}
I can see that this is getting the json objs but when I do a search I don't see any values in the object, I'm guessing because its not being passed in the searchUser()
searchUser() {
this.isLoading = true;
if(!this._searchService.getUser()){
setTimeout(() => {
this.isLoading = false;
}, 500)
}
}
Html input structure:
<input type="text" name="UserEmail" [(ngModel)]="customerEmail" placeholder="Search customer email"> <br>
<button (click)="UserCustomer()" class="omni-btn search-btn float-shadow">Search</button>