Sam Sam - 5 months ago 18
AngularJS Question

How can I change a value inside of ng-repeat after the repeat complete?

I have a JSON which provides me a user's working experiences info. But country and city's are provided in a code format (TR,DE etc.)
I am using ng-repeat to pass them into html like this

<div ng-repeat="e in experiences">
<span>{{e.Name}}</span>
<span ng-init="changeCodeToFullName(e.Country)">{{vm.CountryFullName[$index]}}</span>
</div>


I am using ng-init to convert Country Code to full name. changeCodeToFullName is an angular service written by me, Is this a correct method? If it is, I can't access the dom to change CountryFullName value. I tried to access them in JS file like
vm.CountryFullName[0]="TEST"
but it didn't worked. I need to use e.Country variable after, therefore I can't change the original .e.Country value.

How can I access a variable inside of ng-repeat after ng-repeat completed?

Answer

How about using a custom filter:

<div ng-repeat="e in experiences">
    <span>{{e.Name}}</span>
    <span>{{e.Country | changeCodeToFullName}}</span>
</div>

angular.module('App').filter('changeCodeToFullName', function(YourService) {
    return function(country) {
        return YourService.getFullCountryName(country)
    }
})

Here's an example: http://codepen.io/rustydev/pen/YWyqJB

Comments