alisahinozcelik / angular2-viewport

Angular 2 Viewport Directives & Services
MIT License
14 stars 12 forks source link

Problem with 'unbind' function in Scroll Service #2

Open gbagretsov opened 7 years ago

gbagretsov commented 7 years ago

I'm using Angular 2 with Jasmin. Unfortunately, all my tests fail because of error in Angular Viewport code.

TypeError: Cannot read property 'removeEventListener' of undefined
        at ScrollService.unbind (webpack:///~/angular2-viewport/dist/services/scroll.service.js:46:0 <- config/spec-bundle.js:46436:15)
        at ScrollableContentDirective.ngOnDestroy (webpack:///~/angular2-viewport/dist/directives/scrollable-content.directive.js:22:0 <- config/spec-bundle.js:67626:21)
        at Wrapper_ScrollableContentDirective.ngOnDestroy (/ViewportModule/ScrollableContentDirective/wrapper.ngfactory.js:14:16)
...

So I tried to change the function that causes a problem in such a way:

    unbind(target) {
        this.boundSet.delete(target);
        if (target) // added this line
        target.removeEventListener('scroll', this.handler);
    }

And everything worked well. I would be really glad if you add this fix in the next version or solve the problem in some other way.

alisahinozcelik commented 7 years ago

hi @gbagretsov , thanks for your feedback. Seems it's a bug about scrollable-content directive. I will be fixing it.

gnanavelshenll commented 7 years ago

Hi, I'm getting these error.

D:/xampp/htdocs/angular2/hhwtdemo/node_modules/angular2-viewport/node_modules/@angular/core/src/errors.d.ts (9,33): Initializers are not allowed in ambient contexts.) D:/xampp/htdocs/angular2/hhwtdemo/node_modules/angular2-viewport/node_modules/@angular/core/src/errors.d.ts (10,43): Initializers are not allowed in ambient contexts.) D:/xampp/htdocs/angular2/hhwtdemo/node_modules/angular2-viewport/node_modules/@angular/core/src/errors.d.ts (11,42): Initializers are not allowed in ambient contexts.) D:/xampp/htdocs/angular2/hhwtdemo/node_modules/angular2-viewport/node_modules/@angular/core/src/errors.d.ts (12,43): Initializers are not allowed in ambient contexts.) D:/xampp/htdocs/angular2/hhwtdemo/node_modules/angular2-viewport/node_modules/@angular/core/src/errors.d.ts (13,35): Initializers are not allowed in ambient contexts.)