Hope You Have A Simple Idea About AngularJS And ng-init.If You Are New To These Please Click Here Before Start.
Lets Start With Simple AngularJS Code Along With A Data Array Which Contains Array Of Names.
1 2 3 4 5 6 7 8 9 | <html> <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script> </head> <body ng-app=""> <div ng-init="Names=['Nifal','Gowtham','Dinesh','Hudhaifa','Sam','Anderson']"> </div> </body> </html> |
Now Lets Bind These Names Into A Un-Ordered List. ng-repeat Will Loop Through The Array Just Like A Simple For Each Loop In JQuery. So Lets Do It. I Will Loop Through All The Names And Bind It Inside The <li> Tag Using AngularJS Expression.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <html> <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script> </head> <body ng-app=""> <div ng-init="Names=['Nifal','Gowtham','Dinesh','Hudhaifa','Sam','Anderson']"> <ul> <li ng-repeat = "Name in Names"> {{Name}} </li> </ul> </div> </body> </html> |
If You See This In Browser You Will Get The Following Output.
- Nifal
- Gowtham
- Dinesh
- Hudhaifa
- Sam
- Anderson
- lowercase : Converts A String To Lower Case.
- uppercase : Converts A String To Upper Case.
- filter : Selects A Subset Of Items From An Array.
- orderby : Order The Array Elements By Using Given Expression.
- currency : Formats A Number Into Currency.
1 | {{ Name | uppercase }} |
If You Want To Make It Lowercase Simply Use Replace The "uppercase" With "lowercase".
1 | {{ Name | lowercase }} |
Lets See How We Can Use Filters.This Is How We Create Strings In AngularJS. For That I'm Using A Text Field To Enter The Filter Text.
1 | Filter Text: <input type="text" ng-model="FilterText"> |
Lets Apply This Filter To Our Code.
1 | ng-repeat = "Name in Names | filter:FilterText" |
Lets See Our Full Code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <html> <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script> </head> <body ng-app=""> Filter Text: <input type="text" ng-model="FilterText"> <div ng-init="Names=['Nifal','Gowtham','Dinesh','Hudhaifa','Sam','Anderson']"> <ul> <li ng-repeat = "Name in Names | filter:FilterText"> {{ Name | uppercase }} </li> </ul> </div> </body> </html> |
Hope You Had Good Knowledge About AngularJS Expressions And Variables.
Check My Next Article About AngularJS Controllers.
Check My Next Article About AngularJS Controllers.
No comments:
Post a Comment