Here I created a small function to get the list values through "forEach" function of Angularjs. In the given functionality, I get the list items and push it in to the "listTextVal" array.
Here are the complete Angular functionality and HTML Code.
HTML
<body ng-app="myAwesomeApp">
<div ng-controller="listTextCtrl">
<ul class="items">
<li>First</li>
<li>Second</li>
<li>Third</li>
<li>Four</li>
<li>Five</li>
<li>Six</li>
</ul>
</div>
</body>
In above code, I made a list of items. I just put hardcore items in ul tag and My main concern is to get list text value by using "foreach" method.
Below I mentioned a code packet of Angularjs and AngularJs minified file. In below Code, I just used a simple method, in which I get the "ul" container through class name and after that I find number of children in the container. I already defined an array with "listTestVal" name. In the array I push all the container child length and value and in last I put console log to check the result.
Angularjs Functonality
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script type="text/javascript">
angular.module('myAwesomeApp', []).controller('listTextCtrl', function($scope) {
$scope.listTextVal = [];
var message = document.getElementsByClassName("items");
children = angular.element(message)[0].children;
angular.forEach(children, function(value) {
$scope.listTextVal.push(value.innerHTML);
console.log(value);
});
});
</script>
0 Comment(s)