如何动态更新Popular内容AngularJS Bootstrap

时间:2016-10-02 13:05:29

标签: javascript angularjs twitter-bootstrap angular-ui-router

我使用自定义AngularJs指令来创建bootstrap popover,但是当make popover popover内容无法更改并且它已修复时。

 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'
                });
            }
        };
    });

我的HTML是:

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

typeMessage 应根据用户行为进行更改,但它只显示初始消息,而不会在弹出窗口打开时更改内容。

1 个答案:

答案 0 :(得分:4)

您应该将范围与&#39; @&#39;绑定以反映变化

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'
                });
            }
        };
    });

更新

Plunker

单击单选按钮时,弹出将消失,弹出内容将更新。