Skip to content

Commit

Permalink
You can't use tabs in a modal unless you re-init the tabs plugin afte…
Browse files Browse the repository at this point in the history
…r the modal has been rendered and shown. This fixes that by hooking into the modal ready callback and re-initing the tabs inside the modal.
  • Loading branch information
charleshimmer committed Mar 2, 2016
1 parent 3f9ef57 commit fb5cd59
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/angular-materialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -846,22 +846,32 @@
link: function (scope, element, attrs) {
$timeout(function () {
var modalEl = $(attrs.href ? attrs.href : '#' + attrs.target);
var readyFn = function() {
if (angular.isFunction(scope.ready)) {
scope.$eval(scope.ready());
}
// If we are using tabs in a modal we need to re-init the tabs
// See https://github.com/Dogfalo/materialize/issues/1634
modalEl.find('ul.tabs').tabs();
};
$compile(element.contents())(scope);
element.leanModal({
dismissible: (angular.isDefined(scope.dismissible)) ? scope.dismissible : undefined,
opacity: (angular.isDefined(scope.opacity)) ? scope.opacity : undefined,
in_duration: (angular.isDefined(scope.inDuration)) ? scope.inDuration : undefined,
out_duration: (angular.isDefined(scope.outDuration)) ? scope.outDuration : undefined,
ready: (angular.isDefined(scope.ready)) ? function() {scope.$eval(scope.ready())} : undefined,
ready: readyFn,
complete: (angular.isDefined(scope.complete)) ? function() {scope.$eval(scope.complete())} : undefined,
});

// Setup watch for opening / closing modal programatically.
if (angular.isDefined(attrs.open) && modalEl.length > 0) {
scope.$watch('open', function(value, lastValue) {
if (!angular.isDefined(value)) { return; }
(value === true) ? modalEl.openModal() : modalEl.closeModal();
});
}

});
}
};
Expand Down

0 comments on commit fb5cd59

Please sign in to comment.