Problem with confirm popup response

I have a function in which i am showing a confirm popup. On the basis of the response i am setting data in variable and calling a service.

        var test;
		title: 'Confirm',
		template: 'Are you a sure?'
	}).then(function(res) {
		   test = '1';
		   test = '2';
	});, function(response) {


The problem is when popup is displayed on screen, the control move on to the next line and is called even if user has not clicked on the popup button. It seems like it is working asynchronously. Is there any way to control this behavior.

Looks like service call should be moved inside if(res){} clause…