function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Himanshu Jasuja 9Himanshu Jasuja 9 

Angular js not working in visualforce page and ​I am trying to do this filter, called "myFormat", will uppercase every other character.

<apex:page >
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"/>
     <div ng-app="myapp" ng-controller="mycntrl">
     <ul>
     <li ng-repeat="x in names">
         {{ x | myFormat}}
     </li>
     </ul>
     </div>
 
   <script>
   var myapp = angular.module('myapp', []);
   myapp.filter('myFormat',function(){
   return function(x){
       var i, c, txt = "";
       x=x.split("")
       for(i = 0;i <=x.length; i++){
           c= x[i];
           if(i % 2 == 0){
            c= c.toUpperCase();   
          } 
          txt += c;
        }
        return txt;
     };   
   });
     myapp.controller('mycntrl', function($scope) {
           $scope.names= [
        'Jani',
        'Carl',
        'Margareth',
        'Hege',
        'Joe',
        'Gustav',
        'Birgit',
        'Mary',
        'Kai'
        ];
});   
   </script>
   
   </apex:page>
 
Best Answer chosen by Himanshu Jasuja 9
JethaJetha
Hi Friend,

Please use the below working code : 
<apex:page >
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"/>
     <ul ng-app="myApp" ng-controller="namesCtrl">
<li ng-repeat="x in names">
    {{x | myFormat}}
</li>
</ul>

<script>
var app = angular.module('myApp', []);
app.filter('myFormat', function() {
    return function(x) {
        var i, c, txt = "";
        x = x.split("")
        for (i = 0; i < x.length; i++) {
            c = x[i];
            if (i % 2 == 0) {
                c = c.toUpperCase();
            }
            txt += c;
        }
        return txt;
    };
});
app.controller('namesCtrl', function($scope) {
    $scope.names = [
        'Jani',
        'Carl',
        'Margareth',
        'Hege',
        'Joe',
        'Gustav',
        'Birgit',
        'Mary',
        'Kai'
        ];
});
</script>
   
   </apex:page>

Please let me know if it is working fine for you tooo......

All Answers

Himanshu Jasuja 9Himanshu Jasuja 9
Hi jetha,
still not working ,its shows the undefined as a output instead of name.
JethaJetha
Yes, I was also getting the undefined as output.

Could you please tell me what is your requirement...........

So that I can tell you what exactly needs to be done.....
JethaJetha
Hi Friend,

Please use the below working code : 
<apex:page >
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"/>
     <ul ng-app="myApp" ng-controller="namesCtrl">
<li ng-repeat="x in names">
    {{x | myFormat}}
</li>
</ul>

<script>
var app = angular.module('myApp', []);
app.filter('myFormat', function() {
    return function(x) {
        var i, c, txt = "";
        x = x.split("")
        for (i = 0; i < x.length; i++) {
            c = x[i];
            if (i % 2 == 0) {
                c = c.toUpperCase();
            }
            txt += c;
        }
        return txt;
    };
});
app.controller('namesCtrl', function($scope) {
    $scope.names = [
        'Jani',
        'Carl',
        'Margareth',
        'Hege',
        'Joe',
        'Gustav',
        'Birgit',
        'Mary',
        'Kai'
        ];
});
</script>
   
   </apex:page>

Please let me know if it is working fine for you tooo......
This was selected as the best answer
Himanshu Jasuja 9Himanshu Jasuja 9
Yes.Now its working fine.I found my error in the code too.

Thanks