Angular 2 - best practice question(http)

Hello,

I’m creating a data entry form and it requires multiple dropdown boxes. I’m new so the way I have it coded, it seems kind a fat. it works but I’m going to assume there’s a better way to do this.

Below an example of the code I’m working with and as you can see I’m subscribing multiple times and my question is, is this right? this works so can i get away with this??

each call is pulling in information to populate the dropdown list box.

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;
						}
					},
					error => { 
						if(error){
							console.log('Authentication Failed: ' + <any>error);
							this.errorMessage =  'Authentication Failed.';
						} // End IF					
					 },
					() => {
							console.log('Completed');
				   	}	// END ()						 
	);

this._getPopulateDropDownList.getProjectTaskMethod()		 
				   .subscribe(
						task1 => {
							if(task1.length === 0) {	
                            this.errorMessage =  'failed stage 1';					
							return false;
						}
						else{ 	
                            this.errorMessage =  '';
							this.projectTaskFromDB = task1;							
							return true;
						}
					},
					error => { 
						if(error){
							console.log('Authentication Failed: ' + <any>error);
							this.errorMessage =  'Authentication Failed.';
						} // End IF					
					 },
					() => {
							console.log('Completed');
				   		}	// END ()						 
	);
	);

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.