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

SverkerSöderlund
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,如果那很重要

感谢您的任何反馈!

潘卡·帕克(Pankaj Parkar)

我只能看到一个错误,您应该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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Angular-如何从ng-repeat传递ng-model到函数和作用域

angular.js ng-repeat分区

Angular $ scope函数在ng-repeat之外不起作用

将值推入数组后,ng-repeat不会更新,尝试了$ scope。$ apply()但返回错误

Angular ui.select不绑定到ng-model

Angular 5 ng-repeat实现

Angular 4 ng-repeat实现

将对象推送到$ scope数组后,ng-repeat不会更新

Angular.js在输入中将ng模型与ng-repeat绑定:复选框

ng-repeat Angular中递增的数字

如果从外部ng-repeat $ scope进行的更新也未定义,则ng-repeat中的AngularJS ng-model $ scope是未定义的

在$ scope。$ broadcast()/ $ scope。$ on()中使用angularjs ng-repeat指令

选择不绑定到ng-repeat过滤器的ng-model

Angular JS从静态变为ng-repeat

Angular中的Ng-repeat绑定到对象{{key.value}}中的HTML模板

ng-repeat中的Angular img源

Angular:如何从$ http.get方法外部访问angular $ scope.ng-model_name?

$ scope.variable in ng-repeat

从var angular解除$ scope参数的绑定

Ionic / Angular.js $ scope在没有ng-repeat的情况下不会传递值

Angular ng-repeat创建表问题

$ scope更新后,ng-repeat不更新信息

我想将snapshot.val()分配给$ scope变量$ scope.pending并将其绑定到ng-repeat列表

$ scope更改后,ng-repeat不会第二次触发

Angular ng-repeat什么也没显示

Angular ng-repeat我如何求和

在Angular Radio按钮中将单个ng模型绑定为2 ng-repeat

angular js 中的 ng-repeat 问题,$scope 与视图绑定

angular 嵌套数组的 ng-repeat