I've followed the answer of @Floc and managed to make a custom reusable directive.If someone is stuck with same problem then they can refer this code.
Directive
app.directive('tagInput',function($http){
return{
restrict : 'E',
templateUrl : 'tag-input.html',
scope:{
placeholder : '@',
ngModel : '='
},
link:function(scope,elem,attrs){
scope.addresses = [];
scope.refreshAddresses = function(address){
var params = {address:address,sensor:false};
return $http.get(attrs.url,{params:params})
.then(function(response){
scope.addresses = response.data.results[0].address_components;
})
}
}
}
})
template
<ui-select style="width:50%" ng-model="$parent.ngModel" theme="select2">
<ui-select-match placeholder="{{placeholder}}">{{$select.selected.long_name}}</ui-select-match>
<ui-select-choices repeat="address in addresses track by $index" refresh="refreshAddresses($select.search)" refresh-delay="0" >
<span ng-bind-html="address.long_name| highlight: $select.search"></span>
</ui-select-choices>
And pass required parameters here(in my case it is url and placeholder)
<tag-input url="https://maps.googleapis.com/maps/api/geocode/json" placeholder="hello"></tag-input>