[英]Resize on ng-repeat filter
I currently have an AngularJS application embedded in an iframe which needs to be resized to avoid scrollbars. 我目前在嵌入到iframe中的AngularJS应用程序中需要调整其大小以避免滚动条。 I've got a function in the app that calculates the height of the container and then resizes the iframe.
我在应用程序中有一个函数可以计算容器的高度,然后调整iframe的大小。
Currently I am using a directive (resizeAppPart) which will call the resize function on the last item in the scope. 当前,我正在使用指令(resizeAppPart),它将在范围的最后一项上调用resize函数。
Directive: 指示:
app.directive('resizeAppPart', function () {
return function (scope, element, attrs) {
if (scope.$last) {
Communica.Part.adjustSize();
}
}
});
Layout: 布局:
<tr ng-repeat="task in filteredTasks = (tasks | filter:filters)" resize-app-part>
<td><a href="{{spConfig.spHostUrl}}{{task.visit.ServerRelativeUrl}}/Lists/Actions/DispForm.aspx?ID={{task.Id}}">{{task.Task_x0020_Title}}</a></td>
<td><span ng-repeat="user in task.assignees" ng-show="user.Title != ''">
...
</tr>
This works on the initial load but if I filter the list using any of the search boxes, the directive doesn't run so you either end up with a scrollbar or a few thousand pixels of whitespace - neither are ideal. 这可以在初始加载时起作用,但是如果我使用任何搜索框过滤列表,该指令将不会运行,因此您最终会遇到滚动条或数千个空白-都不是理想选择。
Is there a way to call the directive, or even the function directly, after the table is filtered? 过滤表格后,是否可以调用指令,甚至直接调用函数?
You need to put a $watch
, Use this: 您需要放置一个
$watch
,使用它:
app.directive('resizeAppPart', function ($timeout) {
return function (scope, element, attrs) {
scope.$watch('$last',function(){
Communica.Part.adjustSize();
}
scope.$watch(attrs.filterWatcher,function(){
$timeout(function(){
Communica.Part.adjustSize();
},100)
})
}
});
And slight change in html this way 并以这种方式在html中稍作更改
<tr ng-repeat="task in tasks | filter:filters" resize-app-part filter-watcher={{filters}}>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.