Encountering a small challenge with Angular that is puzzling me. I have a feeling it may be related to scope, but I'm not entirely certain.
Here is the snippet of my HTML:
<i class="icon-question-sign" popover data-placement="top" data-trigger="hover" data-title="Top 10 clients" data-content-compile="<ul><li ng-repeat='client in user.clients | limitTo: 10'>{{client}}</li></ul>"></i>
This is how my directive looks:
app.directive('popover', function($timeout, $compile) {
var linker = function (scope, element, attrs) {
$timeout(function() {
var content = $compile(element.data('content-compile'))(scope);
element.popover({
'html': true,
'content': content
});
}, 200);
}
return {
restrict: 'A',
link: linker
}
});
The outcome correctly repeats the li's for the appropriate length of {{user.clients}}, but fails to render {{client}}. Strangely, it appears empty even though it holds a string value and works when directly added to the HTML without going through the directive. Here is how it currently displays in the DOM:
<ul class="ng-scope"><!-- ngRepeat: client in user.clients | limitTo: 10 --><li ng-repeat="client in user.clients | limitTo: 10" class="ng-scope"></li><li ng-repeat="client in user.clients | limitTo: 10" class="ng-scope"></li><li ng-repeat="client in user.clients | limitTo: 10" class="ng-scope"></li><li ng-repeat="client in user.clients | limitTo: 10" class="ng-scope"></li><li ng-repeat="client in user.clients | limitTo: 10" class="ng-scope"></li><li ng-repeat="client in user.clients | limitTo: 10" class="ng-scope"></li><li ng-repeat="client in user.clients | limitTo: 10" class="ng-scope"></li><li ng-repeat="client in user.clients | limitTo: 10" class="ng-scope"></li><li ng-repeat="client in user.clients | limitTo: 10" class="ng-scope"></li><li ng-repeat="client in user.clients | limitTo: 10" class="ng-scope"></li></ul>
If I substitute {{client}} with something like {{user.email}}, it displays correctly.
I'm unsure of what the issue might be - perhaps I'm overlooking something obvious!