angular.module('demoapp').controller("EventControllerNearPosition", EventControllerNearPosition);
EventControllerNearPosition.$inject = ["$scope", "ApiEventFactory", "ApiPositionFactory", "UserInteractionMessagesFactory", "$location"]
function EventControllerNearPosition($scope, apiEvent, apiPosition, UIMfactory, $location){
UIMfactory.printUserSuccessMessages();
UIMfactory.printUserFailedMessage();
getAllPositions();
function getAllPositions() {
apiPosition.getAllPositions().then(function(data){
$scope.positions = data.requested_positions;
}).error(function(error){
UIMfactory.addUserFailedMessage("Something went wrong, try again!");
$location.path("/");
});
};
$scope.SearchEvent = function(){
apiEvent.showNearbyEvents($scope.position_id).then(function(nearEvents){
$scope.events = nearEvents;
}).error(function(error){
UIMfactory.addUserFailedMessage("Something went wrong when fetching the events, try again!");
$location.path("/");
});
};
};
角碼^
<div class="event-container">
<div>
<h3>Ange position</h3>
<select id="position" data-ng-model="position_id">
<option data-ng-repeat="position in positions" value="{{position.id}}">
{{position.location_name}}
</option>
</select>
</div>
<div class="form-group">
<input type="submit" class="btn btn-default" data-ng-click="SearchEvent()" value="Skicka"/>
</div>
的選擇將不綁定,我從我的API得到的位置。我調試了應用程序並檢查了我獲得了正確的值。我知道類似或「平等」的代碼在其他部分視圖中工作,所以我不明白爲什麼它在這裏不起作用。而且當我按下按鈕來觸發「SearchEvent」時,調試器中就沒有任何反應。我使用Firefox的,如果重要
感謝您的任何反饋!
響應中沒有「數據」。它被稱爲response.requested_position。 Requested_positions是一個包含位置對象的數組 –