Angular $scope.model 不会绑定到 ng-repeat

Angular $scope.model wont bind to ng-repeat

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("/");
    });
};
};

Angular代码^

<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>

select 不会绑定我从 api 获得的位置。我已经调试了应用程序并检查了我是否得到了正确的值。我知道类似或 "equal" 代码在其他部分视图中有效,所以我不明白为什么它在这里不起作用。而且当我按下按钮时将触发 "SearchEvent" 调试器中没有任何反应。如果这很重要,我会使用 firefox

感谢任何类型的反馈!

我只能看到一个错误,你应该从 .then 函数的响应对象中获取 data

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("/");
    });
};

如果我能看到你得到的响应数据,我就能很好地判断。但是就这段代码片段而言, .then() 没有用好。 .then 方法作为 .then(RESPONSE FUNCTION, ERROR FUNCTION) 没有必要使用 .error()

function getAllPositions() {
    apiPosition.getAllPositions().then(function(response){
        $scope.positions = response.data.requested_positions;
    },function(error){
        UIMfactory.addUserFailedMessage("Something went wrong, try again!");
        $location.path("/");
    });
};

我的问题已经解决了。首先,我删除了 response.requested_position(s);

中的 "s"

然后我使用了提交的 answear Pankaj Parkar。除了我没有在 response.data.requested_positions 中使用 "data" 因为我使用的是“$resource”而不是“$http”或其他名称!

感谢大家的反馈!!