T
T
Timofey Yatsenko2014-05-07 13:55:52
Angular
Timofey Yatsenko, 2014-05-07 13:55:52

Why doesn't AngularJs render the list given by $resource?

There is a test directive that renders a list using ng-repeat

filterApp.directive('test', function(){
     return {
        restrict: 'E',
        //require: '^ngModel',
        scope: {
            items: '='
        },
        template: "<select><option ng-repeat='item in items'>{{item.name}}</option></select>",
        link: function($scope, $element, $attrs) {
            
        }
     }
})

Template
<test items="countryItems"></test>
There is a controller that fills the countryItems variable by making a request to the REST service:
$scope.countryItems = Countries.query();
The output is an empty list.
AngularJs has a built-in mechanism that makes it easy to work with asynchronous tasks. In this case, it fills $scope.countryItems with an empty array, and as soon as the data arrives, it fills the array with them.
Theoretically, after filling the array with data, the angular should catch this change and send it to all subscribers, i.e. re-render the list. But that doesn't happen.
Moreover, if you write in the link function:
$scope.$watch('items', function(v) {
                console.log(v);
            }, true);

It can be seen that the updated array still reaches the directive itself, but the view is not redrawn.
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
maxaon, 2014-05-07
@thekip

Everything works plnkr.co/edit/WFHMFMnqKM2MmCQ6tcNx See elsewhere

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question