0
我正在使用ng-init在我的輸入字段中獲取一些默認值。它的工作正常。但是當我將ng-autocomplete添加到輸入字段時,默認值不再顯示在輸入字段中。當使用ng-autocomplete時,在輸入欄中沒有預先填寫默認值
的index.html
<!DOCTYPE html>
<html ng-app=testApp>
<head>
<link rel="stylesheet" href="style.css">
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.js"></script>
<script src="script.js"></script>
<script src="ngAutocomplete.js"></script>
</head>
<body>
<div ng-controller="searchCtrl" ng-init="roomsInit('london')">
<input type="text" ng-autocomplete ng-model="searchLocation" class="form-control input-lg" options="locationFilter">
</div>
</body>
</html>
的script.js
app = angular.module("testApp", ['ngAutocomplete']);
app.controller('searchCtrl', function ($scope, $http) {
$scope.locationFilter = {
country: 'uk',
types: '(cities)'
}; $scope.details2 = '';
$scope.roomsInit = function (location) {
$scope.searchLocation = location;
//below code is not relevant to this case
$http({
url: "/search.json",
method: "GET",
params: {location: $scope.searchLocation,
q: {
daily_price_gteq: $scope.min_price,
daily_price_lteq: $scope.max_price,
room_type_eq_any: [$scope.private, $scope.entire, $scope.shared]
}
},
paramSerializer: '$httpParamSerializerJQLike'
}).success(function (response) {
$scope.rooms = response.rooms;
});
};
});
如果我刪除了NG-自動完成它的工作原理fine.Could有人看看 Here is the plunker
是的..但是,但如何使初始ng-init值加載到輸入字段?在由ng-autocomplete.js提供的pluncker中,他們提到了這個以及ng-autocomplete ng-model =「」... – Abhilash
在我提供的pluncker中,自動完成工作正常。但是如何使默認價值工作? – Abhilash
默認值在技術上有效,但您使用的指令會清除該值。看我的編輯。 –