M
M
Millerish2018-07-31 14:02:06
JavaScript
Millerish, 2018-07-31 14:02:06

How to change data in parents?

How to change the data in the parent?
I try like this:
parent.dart

class Parent{
   int testText = 1;
}

child.dart
class Child extends Parent{
   open(){
    @Output()
     int testText = 2;
   }
}

So the data changes, but only in the child. How to change into parents?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
KnightForce, 2020-02-25
@KnightForce

You create a variable in the open method int testText = 2;.
To change the values ​​in the parent - just write testText = 2;.
If you want to change the values ​​while having a local testText in the method:

class Child extends Parent{
   open(){
    @Output()
     int testText = 2;
     this.testText  = 2;
     // Присвоит значение в переменную у класса, а не в созданную выше.
     // В данном случае у родителя из-за наследования.
   }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question