Html file as content in Bootstrap popover in AngularJS directive

后端 未结 2 897
感情败类
感情败类 2021-02-01 16:40

I have an Angular directive to handle Bootstrap popovers as shown in the code below. In my directive I\'m setting the popover content to a HTML string, which I think is ugly. W

2条回答
  •  一生所求
    2021-02-01 17:24

    To complete the answer from Khahn, if you load a dynamic template, the last part should look like that:

    return {
    restrict: "A",
    scope: {
        item: "=" // what needs to be passed to the template
    },
    link: function(scope, element, attrs) {
    
      getTemplate("user").then(function(popOverContent) {
    
        var options = {
          content: $compile($(popOverContent))(scope),
          placement: "bottom",
          html: true,
          trigger: "hover"
        };
        $(element).popover(options);
    
      });
    }
    

    };

提交回复
热议问题