Skip to content

Instantly share code, notes, and snippets.

@kalbarczyk
Created November 18, 2014 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kalbarczyk/c89687934a1937e53ee7 to your computer and use it in GitHub Desktop.
Save kalbarczyk/c89687934a1937e53ee7 to your computer and use it in GitHub Desktop.
AngularJS - dyrektywa ngClick - 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 xmlns="http://www.w3.org/1999/xhtml" data-ng-app="app">
<head>
<title>ngClick</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.css" />
</head>
<body data-ng-controller="defaultCtrl">
<div class="container">
<div>
<a class="btn btn-default" data-ng-repeat="execute in mountainsList" data-ng-click="execute.execute(execute.metres)">{{execute.mountain}}</a>
</div>
<div class="text-danger">
{{result}}
</div>
</div>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="https://code.angularjs.org/1.3.0-rc.1/angular.js"></script>
<script>
var app = angular.module('app', []);
app.controller('defaultCtrl', function ($scope) {
$scope.result = null;
$scope.mountainsList = [
{ mountain: "Mount Everest", metres: 8850, execute: function (height) { $scope.result= height + ', function 1'; } },
{ mountain: "K2", metres: 8611, execute: function (height) { $scope.result = height + ', function 2'; } },
{ mountain: "Kangczendzonga", metres: 8598, execute: function (height) { $scope.result = height + ', function 3'; } },
{ mountain: "Lhotse", metres: 8501, execute: function (height) { $scope.result = height + ', function 4'; } },
{ mountain: "Makalu", metres: 8463, execute: function (height) { $scope.result = height + ', function 5'; } },
{ mountain: "Cho Oyu", metres: 8201, execute: function (height) { $scope.result = height + ', function 6'; } }];
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment