Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm creating a directive that renders a list of content from a method passed in via an attribute. In addition to passing a method to get the data from, it accepts two attributes to set a class on the ul and li elements rendered in the list. When I set the class on the li element, it works fine. When I try to set a class on the ul, chaos ensues: the ng-repeat no longer works as expected and it throws an exception "undefined is not a function"

Here's a simplified version of the directive that has the issue.

var myApp = angular.module('myApp',[]).
directive('contentList',function(){
   return {
       restrict: 'E',
       replace: true,
       transclude: true,
       scope: {
           method:'&',
           ulclass: '@',
           liclass: '@'
       },
       template: '<div class="content-list-wrapper"> ' +
                    '<div class="content-loader" ng-show="loading"><i>Loading...</i></div>' +
       '<ul class="content-list {{ulclass}}">' +
                        '<li class="content-list-repeat {{liclass}}" ng-repeat="item in items" ng-transclude></li>' +
                    '</ul>' +
                '</div>',
       link: function(scope,iElement,iAttrs){
           scope.items = scope.method();
       }
   } ;
});

If you remove {{ulclass}} in the class attribute of the ul element, everything works. I'm baffled why it works for the li, but not the ul.

I've setup a jsfiddle at http://jsfiddle.net/woogychuck/wqU63/

share|improve this question
    
A fellow developer just made an interesting observation. If you remove both divs from the template it works. –  Ian Muir Apr 11 '13 at 20:07
    
Take a look at stackoverflow.com/questions/14388247/…. A little hairy I know.. as I understand, the issue is that you're muddling two scopes (as the ng-repeat creates a child scope, so you can't run ng-transclude inside it). –  Alex Osborn Apr 11 '13 at 21:11
    
I don't think it's an issue with the differing scopes. The liclass variable in the ng-repeat works fine, it's the ulclass that's causing the problem. It's my understanding that the ul and divs causing the issue wouldn't be creating a new scope as there are no directives being used on those elements. –  Ian Muir Apr 12 '13 at 12:44
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.