forked from Apress/pro-angularjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathincrement.js
More file actions
25 lines (25 loc) · 878 Bytes
/
increment.js
File metadata and controls
25 lines (25 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
angular.module("increment", [])
.directive("increment", function () {
return {
restrict: "E",
scope: {
item: "=item",
property: "@propertyName",
restful: "@restful",
method: "@methodName"
},
link: function (scope, element, attrs) {
var button = angular.element("<button>").text("+");
button.addClass("btn btn-primary btn-xs");
element.append(button);
button.on("click", function () {
scope.$apply(function () {
scope.item[scope.property]++;
if (scope.restful) {
scope.item[scope.method]();
}
})
})
},
}
});