简体   繁体   中英

Angularjs populating dropdown with in ng-repeat from different scope

Hi I have following controller which gets data from database using factory which works fine.

My service is

App.factory("pOvRepository", ['$resource', function ($resource) {
    return {

        pw: $resource('/api/pOv/:id', { id: '@id' }, { update: { method: 'PUT' } }),
        ps: $resource('/api/pStatus/:id', { id: '@id' }, { update: { method: 'PUT' } })
    };

}]);

Controller is

App.controller('pOvCtrl', function ($scope, pOvRepository,  $location) {
    $scope.poviews = pOvRepository.pw.query();
    $scope.pS = pOvRepository.ps.query();

The data I get for $scope.pS is

    [{"p_status1":"Up Coming","p_id":1,"proj":[]},
{"p_status1":"In Progress","p_id":2,"proj":[]},
{"p_status1":"On Hold","p_id":3,"proj":[]}]

In my html code I am trying to populate the dropdown with data from $scope.pS

<div ng-controller="pOvCtrl">
 <form ng-repeat="p in poviews">
 <input type="text" ng-model="p.include_in"/>
<select ng-model="p.p_id" ng-options="a.p_status1 as a.p_id for a in pS"></select>
</form>

When I run it, the dropdown does not get populated with the options from $scope.pS Please let me know how I can fix it. Thanks

Hard to tell without seeing your service, you need to specify a callback for the data:

pOvRepository.ps.query({}, function(data) {
    $scope.pS = data;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM