Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

I update an array outside application Angular with apply() function. I notice that for a simple variable it works, but for array the array didn't update. I don't understand why ?

$scope.altLabelFr = [];
if(properties[altLabel]){
    $.each(properties[altLabel], function(key,val){
        if(val["@language"]=="fr"){
            //$scope.altLabelFr.push(val["@value"]);
            $scope.altLabelFr.push(val["@value"]);
        }
    });
    console.log($scope.altLabelFr);// results : [1,2,3]
}

for simple variable :

$.each(properties[prefLabel], function(key,val){
if(val["@language"]=="en"){
    $scope.prefLabelEn = val["@value"]; 
}});

in the html template :

{{altLabelFr}}  // show [] (supposed to show [1,2,3])
{{prefLabelEn }} // show test

Has someone meet this problem before ? Thank you!

share|improve this question
4  
Where is the apply ? – Omri Aharon 22 hours ago
2  
Why don't you just use angular.forEach instead of $.each? – fos.alex 22 hours ago
    
provide a JSFiddle where we could inspect the problem – Bludream 22 hours ago
    
Even better if it is an array just use the native [].forEach() then you have no dependency. – ste2425 21 hours ago
    
This is the link for jsFiddle : jsfiddle.net/tu937w6c – Zakaria Khattabi 19 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.