Created
November 18, 2014 14:23
-
-
Save kalbarczyk/bf7861981d90e81de85f to your computer and use it in GitHub Desktop.
AngularJS - funkcja identity - przykład z naszej książki „AngularJS - Pierwsze kroki”, która ukaże się na początku 2015r. dzięki wydawnictwu Helion.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html data-ng-app="app"> | |
<head> | |
<title>AngularJS - funkcje - angular.identity</title> | |
<meta http-equiv="content-type" content="text/html; charset=iso-8859-2"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.css" /> | |
</head> | |
<body> | |
<div data-ng-controller="defaultCtrl"> | |
<h1>Wersja normalna: <b>{{n | uppercase}}</b></h1> | |
<h1>Wersja według Yody: <b>{{y | uppercase}}</b></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.yoda = function (a, b, c) { | |
return c + b + a; | |
}; | |
$scope.normal = function (a, b, c) { | |
return a + b + c; | |
}; | |
$scope.result = function (fn, a, b, c) { | |
return (fn || angular.identity)(a, b, c); | |
}; | |
$scope.a = 'to '; | |
$scope.b = 'jest '; | |
$scope.c = 'tekst sklejony '; | |
$scope.n = $scope.result($scope.normal, $scope.a, $scope.b, $scope.c); | |
$scope.y = $scope.result($scope.yoda, $scope.a, $scope.b, $scope.c); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment