Skip to content

Instantly share code, notes, and snippets.

@kalbarczyk
Last active August 29, 2015 14:09
Show Gist options
  • Save kalbarczyk/612f6c7db7a86429daf1 to your computer and use it in GitHub Desktop.
Save kalbarczyk/612f6c7db7a86429daf1 to your computer and use it in GitHub Desktop.
AngularJS - funkcja forEach - przykład z naszej książki „AngularJS - Pierwsze kroki”, która ukaże się na początku 2015r. dzięki wydawnictwu Helion.
<!doctype html>
<html data-ng-app="app">
<head>
<title>AngularJS - funkcje - angular.forEach</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.css" />
</head>
<body>
<div data-ng-controller="defaultCtrl">
<h1>Otwórz konsolę aby zobaczyć efekt (F12).</h1>
</div>
<script src="https://code.angularjs.org/1.3.0/angular.js"></script>
<script>
var app = angular.module('app', []);
app.controller('defaultCtrl', function ($scope) {
$scope.mountainsList = [
{ mountain: "Mount Everest", metres: 8850, country: 'Nepal-China' }, { mountain: "K2", metres: 8611, country: 'Pakistan-China' },
{ mountain: "Kangczendzonga", metres: 8598, country: 'Nepal-India' }, { mountain: "Lhotse", metres: 8501, country: 'Nepal-China' },
{ mountain: "Makalu", metres: 8463, country: 'Nepal-China' }
];
angular.forEach($scope.mountainsList, function (value, index) {
console.log(index, value.mountain, value.metres, value.country);
})
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment