AngularJs count array items
home
Run
screen_rotation
fullscreen
cloud_download
<!DOCTYPE html> <html lang="en"> <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script> <script> var myApp = angular.module("myApp", []); myApp.controller("myController", function($scope) { $scope.myArray = ['Car', 'Bus', 'Truck','Train']; $scope.length = ''; $scope.getLength = function() { $scope.length = $scope.myArray.length; alert("Array Length = "+$scope.length); }; }); </script> </head> <body> <div ng-app="myApp"> <div ng-controller="myController"> <button ng-click="getLength()">Click To Get Length</button> <p>Array = {{myArray}}</p> <p>Length = {{length}}</p> </div> </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script> <script> var myApp = angular.module("myApp", []); myApp.controller("myController", function($scope) { $scope.myArray = ['Car', 'Bus', 'Truck','Train']; $scope.length = ''; $scope.getLength = function() { $scope.length = $scope.myArray.length; alert("Array Length = "+$scope.length); }; }); </script> </head> <body> <div ng-app="myApp"> <div ng-controller="myController"> <button ng-click="getLength()">Click To Get Length</button> <p>Array = {{myArray}}</p> <p>Length = {{length}}</p> </div> </div> </body> </html>
Copyrights@tutorialsplane.com