Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Undefined $scope in tabsetTitles Directive #790

Closed
chrismatheson opened this issue Aug 8, 2013 · 13 comments
Closed

Undefined $scope in tabsetTitles Directive #790

chrismatheson opened this issue Aug 8, 2013 · 13 comments

Comments

@chrismatheson
Copy link

Im really not sure what i can do to help here but im getting the following error

TypeError: Cannot read property '$parent' of undefined
    at link (http://localhost:3000/static/vendor/ui-bootstrap-tpls-0.5.0.js:2677:51)
    at nodeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.js:4774:13)
    at delayedNodeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.js:4930:11)
    at compositeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.js:4365:15)
    at nodeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.js:4768:24)
    at http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.js:4931:13
    at nodeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.js:4768:24)
    at delayedNodeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.js:4930:11)
    at compositeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.js:4353:15)
    at Object.publicLinkFn [as $transcludeFn] (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.js:4270:30) <ul class="nav {{type &amp;&amp; 'nav-' + type}}" ng-class="{'nav-stacked': vertical}" tabset-titles="!tabsAbove"> 
.directive('tabsetTitles', function($http) {
  return {
    restrict: 'A',
    require: '^tabset',
    templateUrl: 'template/tabs/tabset-titles.html',
    replace: true,
    link: function(scope, elm, attrs, tabsetCtrl) {
      if (!scope.$eval(attrs.tabsetTitles)) {
        elm.remove();
      } else {
        //now that tabs location has been decided, transclude the tab titles in
        debugger;
        tabsetCtrl.$transcludeFn(tabsetCtrl.$scope.$parent, function(node) {
          elm.append(node);
        });
      }
    }
  };
})

At the debugger, i get tabsetCtrl.$scope undefined. Not sure what i should be looking for here to give more info.

@pkozlowski-opensource
Copy link
Member

@chrismatheson could you please provide a minimal reproduce scenario using http://plnkr.co/ ?

We've got a similar bug report here: #776 but I would like to confirm if this is a duplicate or not.

@chrismatheson
Copy link
Author

It sounds like a duplicate, but im not sure i can reproduce yet. This is quite deeply embedded into my angular app, and a very similar template does not throw the same error.

@chrismatheson
Copy link
Author

im definately not using ng-if but i am using ng-show & ng-view

@alexhocksween
Copy link

I seem to be having a similar when using nested tabs.
http://plnkr.co/vO8F68

@raykin
Copy link

raykin commented Aug 9, 2013

@alexhocksween yes, I also found the same error in nested tabs

@raykin
Copy link

raykin commented Aug 9, 2013

@Veabers you patch not fix the problem, but create a new bug in my app which has nested tabs.
also your patch code is not indent correct at
https://github.com/Veabers/bootstrap/blob/5aeafc7651ffe241c58a9160c94dfdd46b0c369f/src/tabs/tabs.js#L85-L86

@raykin
Copy link

raykin commented Aug 9, 2013

To simple fix it, I add a new if check at following line 4, but I dont know why need it when write nested tabs

    link: function(scope, elm, attrs, tabsetCtrl) {
      if (!scope.$eval(attrs.tabsetTitles)) {
        elm.remove();
      } else if (tabsetCtrl.$scope) {
        //now that tabs location has been decided, transclude the tab titles in
        tabsetCtrl.$transcludeFn(tabsetCtrl.$scope.$parent, function(node) {
          elm.append(node);
        });
      }
    }

@raykin
Copy link

raykin commented Aug 9, 2013

sorry about the noise.
The above remove the error, but didnt really fix the bug, cause the child tab disappeared(parent tab showed fine)

@ajoslin
Copy link
Contributor

ajoslin commented Aug 9, 2013

I'll take a look at this tomorrow

@ThomasBeavers
Copy link

You are right. The reason that this fix work for me is that I have the templates inline locally.
I understand that inline templates are not right for your project, but doing that causes the error to occur every time. Moving the link to pre fixed the issue when they are inline.

That might explain why the error occurs on nested tabs, because the template is already in the cache and resolving the promise on the initial request causes the tab link function to occur after the tabset link function. I'm not sure how to fix when using templateURL, but maybe my observations will help.

@ajoslin
Copy link
Contributor

ajoslin commented Aug 12, 2013

I think they are fixing the templateUrl nested directives in 1.2.

I never had time to look at this, is the problem simply nested-templateUrl-directive bug?

@gianni-di-noia
Copy link

I found another issue with the 1.2. Seems related to this one.
Peraphs this plurk can help to debug http://plnkr.co/edit/26bt6yF0gfzjmGdRnwiJ?p=preview

@pkozlowski-opensource
Copy link
Member

Duplicate of #783

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants