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,如果那很重要
感谢您的任何反馈!
我只能看到一个错误,您应该data
从.then
函数的响应对象中删除。
function getAllPositions() {
apiPosition.getAllPositions().then(function(response){
//change in below line
$scope.positions = response.data.requested_positions;
}, function(error){
UIMfactory.addUserFailedMessage("Something went wrong, try again!");
$location.path("/");
});
};
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句