user6038757
user6038757

Reputation:

every odd letter uppercase in angular js

i am using angular ng-repeat to print a list but i need to make every odd letter of the word in uppercase i am sure there is a scope of it with angular js but dont know how please help.

HTML CODE

<ul ng-app="mySite" ng-controller="MyCtrl">
<li ng-repeat="list in listData">
    {{list | myFormat}}
</li>
</ul>

JAVASCRIPT

var app = angular.module('mySite', []);
app.filter('myFormat', function() {
    return function(list) {
        var i, c, txt = "";
        list= list.split("")
        for (i = 0; i < list.length; i++) {
            c = list[i];
            if (i % 2 == 0) {
                c = c.toupperCase();
            }
            txt += c;
        }
        return txt;
    };
});
app.controller('MyCtrl', function($scope) {
    $scope.listData = [
        'Jani',
        'Carl',
        'Margareth',
        'Hege',
        'Joe',
        'Gustav',
        'Birgit',
        'Mary',
        'Kai'
        ];
});

Upvotes: 1

Views: 124

Answers (1)

Gaurav Aggarwal
Gaurav Aggarwal

Reputation: 10187

such a silly mistake you are doing

toupperCase(); is wrong use toUpperCase();

Upvotes: 1

Related Questions