下面我使用我的自定義指令type-ahead-custom
兩次一個接一個。如果我多次使用我的指令,屬性總是需要最後一個被盜的值
首次type-ahead-custom="maps"
第二次type-ahead-custom="maps1"
如果我訪問我的指令,它總是返回「maps1」 ..我怎樣才能解決這個裏面的屬性值type-ahead-custom
?
這裏是plunker:https://plnkr.co/edit/hXlNJKboSlA2lAvRqYF1
<form class="form-horizontal" ng-controller="myCtrl" >
<div class="form-group">
<div>
<label for="account" class="col-sm-2 col-md-2 control-label customize-label ">Typeahead 1</label>
<div class="col-sm-8">
<div class="inner-addon right-addon">
<input type="text" ng-model="selectedOptions.planes" uib-typeahead="plane as plane.formatted_address for plane in search($viewValue)" type-ahead-custom="maps" typeahead-loading="loadingdata" typeahead-no-results="noResults" class="form-control ng-valid ng-dirty ng-valid-parse ng-touched" aria-autocomplete="list" aria-expanded="false" aria-owns="typeahead-4-8758" />
</div>
</div>
</div>
</div>
<div class="form-group">
<div>
<label for="account" class="col-sm-2 col-md-2 control-label customize-label ">Typeahead 2</label>
<div class="col-sm-8">
<div class="inner-addon right-addon">
<input type="text" ng-model="selectedOptions.plants" uib-typeahead="plane as plane.formatted_address for plane in search($viewValue)" type-ahead-custom="maps1" typeahead-loading="loadingdata" typeahead-no-results="noResults" class="form-control ng-valid ng-dirty ng-valid-parse ng-touched" aria-autocomplete="list" aria-expanded="false" aria-owns="typeahead-4-8758" />
</div>
</div>
</div>
</div>
</form>
//代碼放在這裏
var exampleApp = angular.module('exampleApp', ['ui.bootstrap']);
exampleApp.directive('typeAheadCustom', function($http, $q) {
return {
link: function($scope, $element, $attributes) {
$scope.search = function(newValue) {
console.log($attributes.typeAheadCustom);
var dfr = $q.defer();
$http.get('//maps.googleapis.com/maps/api/geocode/json', {
params: {
address: newValue,
sensor: false
}
}).success(function(data) {
dfr.resolve(data.results);
});
return dfr.promise;
};
}
}
});
exampleApp.controller('myCtrl', function($http,$scope) {
$scope.selectedOptions = {};
});
感謝...如果我做隔離scope..will我仍然能夠從UIB-預輸入火了搜索功能 – whippits
@whippits而更好的小費be..move'指令內部UI的typeahead' template only ..並且使用'scope:{...}'''將外部世界中的值傳遞給指令隔離範圍' –
它是否會加註..? –