来自 API 的工具提示数据未初始化
tooltip data coming from api not initialized
我是创建的工具提示指令。 但是数据来自 API,所以在页面加载指令初始化,然后通过 api 加载数据,数据稍后出现,因此指令没有正确初始化。
我该如何处理?
.HTML::
<strong href="#" pop-over items="result" title="detailes" display-length="5">{[{ result.name}]}
Javascript :
listingApp.directive('popOver', function ($compile) {
var itemsTemplate = "<ul class='unstyled'><li>{{items}}</li></ul>";
var getTemplate = function (contentType) {
var template = '';
switch (contentType) {
case 'items':
template = itemsTemplate;
break;
}
return template;
}
return {
restrict: "A",
transclude: true,
scope: {
items: '=',
title: '@',
//popContent: '=',
displayLength:'@'
},
transclude: true,
template: "<span ng-transclude></span>",
link: function (scope, element, attrs) {
debugger;
// console.log('^^^^^^^^^^^^^^^'+attrs.popContent);
var popOverContent;
if (scope.items) {
var html = getTemplate("items");
popOverContent = $compile(html)(scope);
}
var options = {
content: popOverContent,
placement: "bottom",
html: true,
title: scope.title,
trigger: "hover"
};
if ((scope.items || '').length > attrs.displayLength) {
$(element).find('.display_data').text(scope.items.substring(0, attrs.displayLength));
element.attr('title', scope.items);
$(element).find('.view_more').popover(options);
} else {
$(element).find('.display_data').text(scope.items);
}
}
};
});
尝试用$timeout包装您的 .popover 插件:
$timeout(function() {
$(element).find('.view_more').popover(options);
});
相关文章:
- jquery数据表在初始化时设置宽度
- 使用AngularJS初始化数据表
- 在 Angular 服务中初始化数据的位置
- 初始化数据的正确方法
- 如何在使用 jQuery 创建表后初始化数据表.js加载函数
- 反应“考虑初始化数据以消除歧义”问题
- 数据表 jQuery 无法重新初始化数据表
- R: 如何在Shiny中初始化数据表FixedColumns javascript
- 如何避免在初始化数据绑定下拉列表时触发订阅
- 刷新数据表时出错-无法重新初始化数据表
- jqgrid treeGrid Json,如何在初始化数据时扩展所有节点
- 在模态表上初始化数据表时出现Ajax错误
- 在Highchart中,如何初始化数据中的字符串值
- 如何在AngularJS中通过AJAX加载数据后重新初始化数据表?
- 延迟页控制器的执行,直到收集到初始化数据
- JSON在服务中初始化数据
- 如何重新初始化数据表
- 使用新的 API 重新初始化数据表
- 从 json 变量 d3js (javascript) 初始化数据
- 用PHP初始化数据表