Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions chapter4/recipe3/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
<link rel="stylesheet" href="css/bootstrap.css">
</head>
<body ng-app="MyApp">
<ul ng-init="names = ['Peter', 'Anton', 'John']">
<li ng-repeat="name in names | exclude:'Peter'">
<span>{{name}}</span>
</li>
</ul>
<input type="text" ng-model="text" placeholder="Enter text"/>
<p>Input: {{ text }}</p>
<p>Filtered input: {{ text | reverse: { suffix: "!"} }}</p>
</body>
</html>
18 changes: 11 additions & 7 deletions chapter4/recipe3/js/app.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
var app = angular.module("MyApp", []);

app.filter("exclude", function() {
return function(input, exclude) {
var result = [];
app.filter("reverse", function() {
return function(input, options) {
input = input || "";
var result = "";
var suffix = options["suffix"] || "";

for (var i=0; i<input.length; i++) {
if (input[i] !== exclude) {
result.push(input[i]);
}
result = input.charAt(i) + result;
}

if (input.length > 0) result += suffix;


return result;
};
});
});
15 changes: 15 additions & 0 deletions chapter4/recipe4/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<html>
<head>
<meta charset='utf-8'>
<script src="js/angular.js"></script>
<script src="js/app.js"></script>
<link rel="stylesheet" href="css/bootstrap.css">
</head>
<body ng-app="MyApp">
<ul ng-init="names = ['Peter', 'Anton', 'John']">
<li ng-repeat="name in names | exclude:'Peter'">
<span>{{name}}</span>
</li>
</ul>
</body>
</html>
14 changes: 14 additions & 0 deletions chapter4/recipe4/js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var app = angular.module("MyApp", []);

app.filter("exclude", function() {
return function(input, exclude) {
var result = [];
for (var i=0; i<input.length; i++) {
if (input[i] !== exclude) {
result.push(input[i]);
}
}

return result;
};
});
Loading