farzad
farzad

Reputation: 654

How to dynamically update popover content AngularJS Bootstrap

I use custom AngularJs directive for create bootstrap popover but when make popover popover content can't change and it's fix .

 app.directive('nextLevel', function () {
        return {
            restrict: 'EA',
            template: '<a ui-sref="register" tabindex="0" linkdisabled="{{type}}"
 class="btn btn-block btn-success ng-class: {disabled: !(type)}" role="button" >next</a>',
            link: function (scope, el, attrs){
                $(el).popover({
                    trigger: 'click',
                    html: true,
                    toggle:'popover',   
                    title: 'notice !!',
                    content: attrs.popoverHtml,
                    placement: 'top'
                });
            }
        };
    });

my html is :

<next-level id='pop' popover-html='{{typeMessage}}'></next-level>

typeMessage should be change depending on user behavior but it's only show initial message and not change content when popover open .

Upvotes: 1

Views: 5530

Answers (1)

Ravi Teja
Ravi Teja

Reputation: 1107

You should isolate the scope with '@' binding inorder to reflect the change

app.directive('nextLevel', function () {
        return {
            restrict: 'EA',
            scope:{ popoverHtml:'@'}, // Isolated the scope 
            template: '<a ui-sref="register" tabindex="0" linkdisabled="{{type}}"
 class="btn btn-block btn-success ng-class: {disabled: !(type)}" role="button" >next</a>',
            link: function (scope, el, attrs){
                $(el).popover({
                    trigger: 'click',
                    html: true,
                    toggle:'popover',   
                    title: 'notice !!',
                    content: scope.popoverHtml,  // Access the popoverHtml html
                    placement: 'top'
                });
            }
        };
    });

Update:

Plunker

When you click on radio button, pop over will disappear and pop over content will be updated.

Upvotes: 4

Related Questions