Hello Everybody,

I have a user entry form and the form has several drop down menus; 5 to be 
exact, and there populated at initial page load so that the user can select 
from. In order to populate the drop down menus I making several HTTP 
request which I'm not sure if its the best way to make the request to the 
database. My code seems to be a  bit *fat* and i'm thinking there's better 
way to handle the request.

Is there a better way to make the http request, am I over coding the script 
or what I am doing is fine??


*component.ts*
as you can see, I'm calling each individual  methods to populate the drop 
down menu and I'm doing this 5 times.
ngOnInit(){         
          *  this._getPopulateDropDownList.getProjectListMethod()*  
  .subscribe(
data1 => {
if(data1.length === 0) { 
                                             this.errorMessage =  'failed 
stage 1'; 
     return false;
}
else{ 
                                             this.errorMessage =  '';
     this.projectListFromDB = data1; 
     return true;
}
}  
);

*this._getPopulateDropDownList.getProjectTaskMethod()*  
  .subscribe(
task1 => {
if(task1.length === 0) { 
                                             this.errorMessage =  'failed 
stage 1'; 
      return false;
}
else{ 
                            this.errorMessage =  '';
    this.projectTaskFromDB = task1; 
    return true;
}
},



*service.ts*
In my service.ts, you can see that I have the the observables to get the 
data but again I'm doing this 5 with smilar coding.. the drop down menus 
are not dependent on the above drop down menu 
 *getProjectListMethod(): Observable<any>{  *     
        let headers = new Headers({'Content-Type': 'application/json' });
        let options = new RequestOptions({ headers: headers });             
   
      
        return this._http
                .post(this.URLProjectList, options)
                .map((res: Response) =>  res.json())                
                .catch (this.handleError);                
    } //END - getUserListMethod

   * getProjectTaskMethod(): Observable<any>{*       
        let headers = new Headers({'Content-Type': 'application/json' });
        let options = new RequestOptions({ headers: headers });             
   
      
        return this._http
                .post(this.URLProjectTask, options)
                .map((res: Response) =>  res.json())                
                .catch (this.handleError);                
    } //END -




-- 
You received this message because you are subscribed to the Google Groups 
"Angular" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to