angularjs - mwl-calendar 不适用于指令
问题描述
我在 angularjs 中创建了一个指令来更改我的角度月视图中的文本,但是当我将视图从周切换到月时,它不会显示我的数据。
<script id="customMonthCell.html" type="text/ng-template">
<div size-elt class="cal-month-day {{day.cssClass}}">
<span
class="pull-right"
data-cal-date
ng-click="vm.calendarCtrl.dateClicked(day.date)"
ng-bind="day.label">
</span>
<small style="position: absolute; bottom: 10px; left: 5px">{{monthCalendarDayDivWidth}}
<div style="display:inline-block;margin-bottom: 5px;" ng-repeat="(petitTitle, events) in day.groups track by petitTitle">
<span ng-if="events.length > 1 && monthCalendarDayDivWidth > 130">
{{events[0].description}}
</span>
<span ng-if="events.length > 1 && monthCalendarDayDivWidth <= 130">
{{littleTitle}}
</span>
</div>
</small>
</div>
</script>
tabs.directive('sizeElt', ['$window', function ($window) {
return {
link: link,
restrict: 'A'
};
function link(scope, element, attrs) {
angular.element($window).bind('resize', function () {
scope.windowWidth = $window.innerWidth;
scope.monthCalendarDayDivWidth = element[0].offsetWidth
scope.$apply();
});
angular.element($window).bind('load', function () {
scope.windowWidth = $window.innerWidth;
scope.monthCalendarDayDivWidth = element[0].offsetWidth
scope.$apply();
});
}
}]);
这是我加载页面的时候
这是我点击周视图并返回月视图的时候
就像没有定义monthCalendarDayDivWidth但是如果我在切换视图时强制它仍然不起作用
$scope.monthCalendarDayDivWidth = $scope.windowWidth > 1080 ? 140 : 110
解决方案
我修改了我的指令,所以当我在日历中切换视图时,我可以看到数据
tabs.directive('sizeElt', ['$window', function ($window) {
return {
link: link,
restrict: 'A'
};
function link(scope, element, attrs) {
angular.element($window).bind('resize', function () {
scope.windowWidth = $window.innerWidth;
scope.monthCalendarDayDivWidth = element[0].offsetWidth
scope.$apply();
});
if (element.offsetWidth !== 0 || element.offsetHeight !== 0) {
setTimeout(function () {
scope.windowWidth = $window.innerWidth;
scope.monthCalendarDayDivWidth = element[0].offsetWidth
scope.$apply();
}, 0);
}
}
}]);
推荐阅读
- java - 如何使用 Java 从真实文件中读取?
- vagrant - 在 vagrantFile 中添加 vagrant 供应代码
- google-apps-script - 一种在 Google 工作表中搜索单词并突出显示包含它们的行的方法
- python - 我无法在 Windows 中安装 pyaudio
- c++ - 将 POD“合并”为一个
- php - 从未初始化的类型化属性中找出类型
- elixir - 当你在 ecto 中进行 group_by 时如何选择?
- docker - Jenkins Build Fail- Docker Section
- excel - 根据您在二维数组中的总单元格上的位置查找单元格
- javascript - How to print only one specific vue component?