Skip to content

Different uiScrollViewport schemes when using as a component #239

@ornic

Description

@ornic

I am trying to use great ui-scroll module inside one of the components. This is a (surprise!) list, but i need to show it both inside window (no viewport) or inside popup (with viewport).

The only way I know to tell ui-scroll about viewport is ui-scroll-viewport attribute. And the only way I can tell Angular about optional attribute is ng-attr- prefix. I want it to be optional attribute, since I hate to copy-paste the same code in ng-switches.

And this is a place when things get interesting. According to angular/angular.js#16441 ui-scroll gets information about ui-scroll-viewport attribute before evaluation of ng-attr-ui-scroll-viewport value.

May be someone will point me to more "right" solution. But for now I had to patch ui-scroll.js file.

  1. I send the max-height style inside some param to the component
    <ul class="list-group" style="overflow-x: hidden" ng-attr-ui-scroll-viewport="$ctrl.checkRestrictHeight()" ng-style="{'min-height': '1px', 'max-height': $ctrl.checkRestrictHeight()}">

        <a class="list-group-item" ui-scroll="survey in $ctrl.itemsSource" start-index="$ctrl.startPosition" buffer-size="30" adapter="$ctrl.scroll"
...
  1. I check the result of $eval for ng-attr-ui-scroll-viewport value
function Viewport(elementRoutines, buffer, element, viewportController, $rootScope, padding) {
  var topPadding = null;
  var bottomPadding = null;

    //ADD

    let ngAttrEval = true;
    if (viewportController && viewportController.viewport && viewportController.viewport[0].attributes && viewportController.viewport[0].attributes.hasOwnProperty('ng-attr-ui-scroll-viewport') && !viewportController.viewport[0].attributes.hasOwnProperty('ui-scroll-viewport')) {
        ngAttrEval = false;
        if (viewportController.scope) {
            ngAttrEval = viewportController.scope.$eval(viewportController.viewport[0].attributes['ng-attr-ui-scroll-viewport'].value);
        }
    }

    //CHANGE

    var viewport = viewportController && viewportController.viewport && ngAttrEval ? viewportController.viewport : angular.element(window);
    var container = viewportController && viewportController.container && ngAttrEval ? viewportController.container : undefined;
    var scope = viewportController && viewportController.scope && ngAttrEval ? viewportController.scope : $rootScope;

...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions