Skip to content

Commit 90f360c

Browse files
committed
refactor(ionicTouch): factor ngClick logic out to reusable service
Addresses #802
1 parent baa04cd commit 90f360c

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

js/ext/angular/src/directive/ionicTouch.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11

22
// Similar to Angular's ngTouch, however it uses Ionic's tap detection
3-
// and click simulation. ngClick
3+
// and click simulation. ngClick
44

55
(function(angular, ionic) {'use strict';
66

7-
87
angular.module('ionic.ui.touch', [])
98

109
.config(['$provide', function($provide) {
@@ -15,17 +14,16 @@ angular.module('ionic.ui.touch', [])
1514
}]);
1615
}])
1716

18-
.directive('ngClick', ['$parse', function($parse) {
19-
17+
/**
18+
* @private
19+
*/
20+
.factory('$ionicNgClick', ['$parse', function($parse) {
2021
function onTap(e) {
2122
// wire this up to Ionic's tap/click simulation
2223
ionic.tapElement(e.target, e);
2324
}
24-
25-
// Actual linking function.
26-
return function(scope, element, attr) {
27-
28-
var clickHandler = $parse(attr.ngClick);
25+
return function(scope, element, clickExpr) {
26+
var clickHandler = $parse(clickExpr);
2927

3028
element.on('click', function(event) {
3129
scope.$apply(function() {
@@ -42,9 +40,13 @@ angular.module('ionic.ui.touch', [])
4240
scope.$on('$destroy', function () {
4341
ionic.off('tap', onTap, element[0]);
4442
});
45-
4643
};
44+
}])
4745

46+
.directive('ngClick', ['$ionicNgClick', function($ionicNgClick) {
47+
return function(scope, element, attr) {
48+
$ionicNgClick(scope, element, attr.ngClick);
49+
};
4850
}])
4951

5052
.directive('ionStopEvent', function () {

0 commit comments

Comments
 (0)