Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation between pages inheriting the same class breaks ngFor? #5782

Closed
sphaso opened this issue Mar 9, 2016 · 1 comment
Closed

Navigation between pages inheriting the same class breaks ngFor? #5782

sphaso opened this issue Mar 9, 2016 · 1 comment

Comments

@sphaso
Copy link

sphaso commented Mar 9, 2016

Short description of the problem:

The set up:

  • I have two pages, each one has an ngFor with a simple pipe over a collection of (differently) typed items
  • I have an @Injectable () class with some protected fields and methods. The two pages inherit this class

The problem:

  • when I go from the first page to the second, I get an error on the console saying that there's no differ for the type of the first page

The debug:

  • I tried debugging and I see that before going to the second page, the pipe gets called
  • it seems that the return of the pipe is getting evaluated on the second page, and that's why it breaks (removing the pipe in the second template doesn't solve the issue)

If I remove the inheritance from the second page, of course, everything works just fine.

What behavior are you expecting?

Either the pipe transform doesn't get hit, or it doesn't throw an exception.

Steps to reproduce:
Is there a plnkr where I could try to reproduce this?

// master page
 @Injectable ()
 export class MasterPage {

     protected ToRevert : number[] = [];

     onPageDidEnter () {
         this.ToRevert = [];
     }
 }

//a snippet from the template. As you can see the call to the second page is inside an item of a list, is this why the pipe gets called?

 <ion-item *ngFor="#item of Dn | userFilter:inputFilter.value:onlySel:'descrizione'; #i = index"
                           [ngClass]="{green: item.selected}">
                     <ion-row>
                         <ion-col (click)="toggle(item, i)">
                             <span>{{item.descrizione}}</span>
                             <p>Editori: {{item.countEditori}}</p>
                         </ion-col>
                         <ion-col>
                             <a href="#" (click)="gotoEditori(item)"><ion-icon style="float:right;" name="ios-arrow-forward"></ion-icon></a>
                         </ion-col>
                     </ion-row>
                 </ion-item>
             </ion-list>

//the pipe
 @Pipe({
     name: 'userFilter'
 })
 export class UserFilterPipe implements PipeTransform {
     transform(value:any, args:string[]): any {
         let filter = args[0].toLocaleLowerCase();
         let field = args[2];
         let current = (filter && value) ? value.filter(ff => ff[field].toLocaleLowerCase().indexOf(filter) != -1) : value;
         if(args[1]){
             return current.filter(ff => ff.selected);
         }
         return current;
     }
 }

Ionic Version: 2.x

Browser & Operating System: iOS / Android / Chrome

Run ionic info from terminal/cmd prompt:

Cordova CLI: 4.2.0
Gulp version:  CLI version 3.9.1
Gulp local:   Local version 3.9.1
Ionic CLI Version: 2.0.0-beta.17
Ionic App Lib Version: 2.0.0-beta.8
OS: Windows 7 SP1
Node Version: v4.1.2
@sphaso
Copy link
Author

sphaso commented Mar 10, 2016

Turns out that removing @Injectable () from the parent class resolves the issue without breaking inheritance, it was stupid of me to use that annotation in the first place. Sorry. Closing this.

@sphaso sphaso closed this as completed Mar 10, 2016
@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants