小编典典

AngularJS ng-click在弹出窗口内损坏

angularjs

我正在尝试编写指令以加载部分html文件,针对范围对其进行编译并将其用作Bootstrap弹出窗口内容。

但是,我停留在一个非常基本的步骤上,在popover范围内编写hide()方法,以便可以使用轻松关闭它ng-click=hide()


这个问题已经解决,而插件正在解决其他问题;-)。

更新:急救人员:http
://plnkr.co/edit/QH3NQh?p=preview

.directive('uiPopover', ['$compile', '$http', function($compile, $http) {
return {
    restrict: 'A',
    scope: {
        hide: '&hide' // did not understand what is this
    },
    link: function postLink(scope, element, attr, ctrl) {
        console.warn('postLink', arguments, this);

        // scope is the anchor scope
        scope.name = "Hello"; // Using {{name}} is working
        scope.hide = function() { // Using ng-click="hide()" is not working :(
            console.log('in');
            element.popover('hide');
        }

        $http.get(attr.uiPopover).success(function(data) {
            element.popover({
                content: $compile(data)(scope), // popover content will get a new scope that I need to put hide() on.
                html: true
            });
        });


    }
}
}]);

阅读 189

收藏
2020-07-04

共1个答案

小编典典

请参阅此google
group主题
,特别是Andy的小提琴。困难似乎是popover小部件/组件创建了一个新的DOM元素,该元素放置在ui-
popover指令所在的作用域之外。

2020-07-04