나는 @Floc의 답을 따라 왔고 사용자 지정 재사용 지시문을 만들었습니다. 누군가가 동일한 문제를 고집하면이 코드를 참조 할 수 있습니다.
지침
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;
})
}
}
}
})
템플릿
<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>
그리고 여기에 필요한 매개 변수를 전달
<tag-input url="https://maps.googleapis.com/maps/api/geocode/json" placeholder="hello"></tag-input>
(내 경우는 URL과 자리 표시 자입니다)