Search code examples
angularjs-directivebootstrap-popover

ng-repeat within pop-over angular directive


I am trying to use boot-strap pop-over within angular. I have created a directive & trying to attach the content dynamically using $compile. However $compile is not replacing my contents. Here is the fiddle.

http://jsfiddle.net/gurukashyap/4ajpyjyf/

customDirectives = angular.module('customDirectives', []);
function MyCtrl($scope) {
    $scope.items = ['abc','dev','it'];


}

    customDirectives.directive('custPopover', function ($compile) {
        return {
            scope : {
                items : '=items'  
            }, 
            restrict: 'A',

            template: '<span>Label</span>',
            link: function (scope, el, attrs) {
                scope.label = attrs.popoverLabel;
                var temp = '<ul><li ng-repeat="item in items">{{item}}</li></ul>';
                var contents = $compile(temp)(scope);
                console.log(scope);
                $(el).popover({
                    trigger: 'click',
                    html: true,
                    content:  contents,
                    placement: attrs.popoverPlacement
                });
            }
        };
    });

    angular.module('CustomComponents', ['customDirectives']);

Any help appreicated


Solution

  • You just passed the parameter wrong. items: '=newvar'

    http://jsfiddle.net/4ajpyjyf/2/