$scope.clickfunction = function(arg){
  var url ="";
  var httppromise = $scope.promiseufunction(arg); // return a http promise 
    httppromise.then(function(res){
     if(res){
         url ="path/"
         $('#htmlelement').attr('href', url);
       }else{
        url="path2/"
          $('#htmlelement').attr('href', url);
        };
       });
      }  //<---- this line execute before the inner function of promise.then
I have an anchor tag with ng-click that calls the above clickfunction function. I rely on the promise to resolve and update the href attribute, but I found that the end of function have reached before the innner function of promise.then(), and that causes my ng-click not work properly as i expected , href attribute updated after the ng-click event on href.
How can solve this,to make sure the inner function of promise work before reach the end of this function?
 
    