【发布时间】:2014-04-24 09:21:35
【问题描述】:
我正在尝试开发类似 FaceBook 的通知(例如,当收到好友请求时,右上角会出现一个带有通知数量的图标)。
为此我写了一个弹出指令。
app.directive('popOver', function ($compile) {
var itemsTemplate = "<div ng-repeat='item in items'>{{item}} <br/><hr/></div> ";
var getTemplate = function (contentType) {
var template = '';
switch (contentType) {
case 'items':
template = itemsTemplate;
break;
}
return template;
}
return {
restrict: "A",
transclude: true,
template: "<span ng-transclude></span>",
link: function (scope, element, attrs) {
var popOverContent = "<div></div>";
if (scope.items) {
var html = getTemplate("items");
popOverContent = $compile(html)(scope);
}
var options = {
content: popOverContent,
placement: "bottom",
html: true,
title: scope.title
};
$(element).popover(options);
},
scope: {
items: '=',
title: '@'
}
};
});
项目填充在控制器中,我使用 $timeout 从数据库中获取新数据并填充 scope.Items
在 UI 中,我有一个按钮,它显示新通知的数量,单击它我想显示一个带有项目的弹出窗口。问题是当点击按钮时弹出框没有加载新项目。
<button pop-over items="items" class="navbar-btn btn-info round-button" title="Notifications:" > {{newAlertCount}} </button>
【问题讨论】:
标签: angularjs