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

时间:2016-05-15 08:41:57

标签: angularjs scope ng-repeat

$('#test111').on('mouseover', function() {
    (document).getElementById("test222 img:nth-child(2)").style.display = "inline-block";
}).on('mouseout', function() {
    (document).getElementById("test222:nth-child(2)").style.display = "none";
})

角度代码^

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

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

感谢您的任何反馈!

3 个答案:

答案 0 :(得分:2)

我只能看到一个错误,你应该从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("/");
    });
};

答案 1 :(得分:0)

如果能看到你得到的数据,我能判断得很好。但就此代码段而言,.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("/");
    });
};

答案 2 :(得分:0)

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

然后我使用了answear Pankaj Parkar。除了我没有在response.data.requested_positions中使用“数据”,因为我使用“$ resource”而不是“$ http”或其他任何名称!

感谢所有反馈!!