jeudi 17 novembre 2016

How to access a field of another class without missing a data in TypeScript?

By the way, I'm coding on TypeScript, Ionic takes part in this. For example we have a class IngridlistPage with following code:

export class IngridlistPage {
public dbingrids: string = "test";
constructor() {};
}

We have a second class IngridsearchPage with following code:

import { IngridlistPage } from '../ingridlistpage'
export class IngridsearchPage {
  ionViewDidLoad() {
    console.log(IngridlistPage['deb']);
   }
}

The result of theese actions in my console is: undefined. I have tried to use 'getter', have tried to initialize in constructor and declare dbingrids out of it, tried to access to Ingridlistpage with .prototype. If I console.log(IngridlistPage), it outputs the object, which contains property dbingrids, but if I access to only property, it outputs "property does not exist on type 'typeof IngridlistPage'"

I can create a new instance of that class and access to property of instance, but this solution is not for me: in the class IngridlistPage I have some methods that changes the value of dbingrids. If I want to add some ingridients from dbingrids to the useringrids and then delete some useringrids (including some ingridients from dbingrids), I have to work with the same variable useringrids.

Thank you for your attention to my question.





Aucun commentaire:

Enregistrer un commentaire