简体   繁体   English

如何动态更新弹出内容 AngularJS Bootstrap

[英]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 .我使用自定义 AngularJs 指令来创建 bootstrap popover,但是当 make popover popover 内容无法更改并且它是 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 :我的 html 是:

<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 . typeMessage应该根据用户行为而改变,但它只显示初始消息,而不是在 popover open 时更改内容。

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.当您单击单选按钮时,弹出窗口将消失并且弹出窗口内容将被更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM