Skip to content

Commit

Permalink
fix(navClear): be sure it runs before ngClick
Browse files Browse the repository at this point in the history
Closes #1047
  • Loading branch information
ajoslin committed Apr 4, 2014
1 parent 3ee5ea7 commit 4f47bf2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
23 changes: 16 additions & 7 deletions js/ext/angular/src/directive/ionicViewState.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,16 +298,25 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
* <a nav-clear menu-close href="#/home" class="item">Home</a>
* ```
*/
.directive('navClear', ['$ionicViewService', function($ionicViewService) {
.directive('navClear', [
'$ionicViewService',
'$location',
'$timeout',
function($ionicViewService, $location, $timeout) {
return {
priority: Number.MAX_VALUE,
restrict: 'AC',
link: function($scope, $element, $attr) {
$element.bind('click', function(){
$ionicViewService.nextViewOptions({
disableAnimate: true,
disableBack: true
compile: function($element) {
return { pre: prelink };

function prelink($scope, $element) {
$element.on('click', function(e){
$ionicViewService.nextViewOptions({
disableAnimate: true,
disableBack: true
});
});
});
}
}
};
}]);
Expand Down
28 changes: 28 additions & 0 deletions js/ext/angular/test/directive/ionicNavClear.unit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
describe('navClear directive', function() {
beforeEach(module('ionic'));
it('should call nextViewOptions on click', inject(function($rootScope, $compile, $ionicViewService) {
spyOn($ionicViewService, 'nextViewOptions');
var el = $compile('<div nav-clear>')($rootScope.$new());
expect($ionicViewService.nextViewOptions).not.toHaveBeenCalled();
el.triggerHandler('click');
expect($ionicViewService.nextViewOptions).toHaveBeenCalled();
expect($ionicViewService.nextViewOptions.mostRecentCall.args[0]).toEqual({
disableAnimate: true,
disableBack: true
});
}));

it('should run its click action before ngClick', inject(function($rootScope, $compile, $ionicViewService) {
spyOn($ionicViewService, 'nextViewOptions');
var el = $compile('<div nav-clear ng-click="method()">')($rootScope.$new());
var done = false;

//navClear should've called nextViewOptions by the time the ngClick handler runs
el.scope().method = function() {
expect($ionicViewService.nextViewOptions).toHaveBeenCalled();
done = true;
};
el.triggerHandler('click');
expect(done).toBe(true);
}));
});

0 comments on commit 4f47bf2

Please sign in to comment.