foundation-apps icon indicating copy to clipboard operation
foundation-apps copied to clipboard

Using `FoundationTabs.activate` throws "$apply already in progress"

Open ricklupton opened this issue 9 years ago • 1 comments

My code calls:

FoundationTabs.activate('outputs-tab');

which causes an "$apply already in progress" error. This is due to the scope.$apply() call in zfTabIndividual, quoted below.

This seems to be similar to #250 which was resolved by checking if a digest is already in progress before calling $apply.

  function zfTabIndividual(foundationApi) {
    var directive = {
      restrict: 'EA',
      transclude: 'true',
      link: link
    };

    return directive;

    function link(scope, element, attrs, ctrl, transclude) {
      var tab = scope.$eval(attrs.tab);
      var id = tab.scope.id;

      tab.scope.transcludeFn(tab.scope, function(tabContent) {
        element.append(tabContent);
      });

      foundationApi.subscribe(tab.scope.id, function(msg) {
        foundationApi.publish(tab.parentContent, ['activate', tab.scope.id]);
        scope.$apply();
      });

    }
  }

ricklupton avatar Aug 10 '15 09:08 ricklupton

I am running into the same issue. It does open the tab though!

If you enclose the publish call in a $timeout, it will not throw the error.

$timeout(function(){ FoundationApi.publish('TAB_ID', 'activate'); });

vincentpalita avatar Dec 21 '15 10:12 vincentpalita