Angular 2 call super method from html

Miquel

I've successfully achieved to inherit a class. I would like to call super method from template but right now what I'm getting is Cannot read property 'presentModal' of undefined:

@Component({})
class Dia {
    constructor(public modalCtrl: ModalController) {
    }

    presentModal() {
        const detailModal = this.modalCtrl.create(AgendaDetails, { showDetails: 8675309 });
        detailModal.present();
    }
}

@Component({
    templateUrl: 'dimarts-tab.html',
})
export class Dimarts extends Dia { }

and in template:

<ion-item text-wrap (click)="super.presentModal()">

I've also tried with $super, $parent with no success. The only working solution at this moment is to create the method in Dimarts and call super there.

Any ideas?

Estus Flask

super is ES6 syntax that cannot be used outside the method where it's used. Given there is Foo class that extends Bar, super keyword is interpreted as Bar in Foo constructor and static methods and as Bar.prototype in instance methods.

class Foo extends Bar {
  foo() {
    super.foo()
  }
}

will be transpiled to

var Foo = /** @class */ (function (_super) {
    __extends(Foo, _super);
    function Foo() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Foo.prototype.foo = function () {
        _super.prototype.foo.call(this);
    };
    return Foo;
}(Bar));

The attempt to use super.presentModal() in template defies the purpose of class inheritance and prototype chains.

Unless presentModal is defined in child class, it is inherited from parent class. It should be:

<ion-item text-wrap (click)="presentModal()">

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

call Angular 2 component method from html event

From Dev

Call a component method from HTML in Angular2

From Dev

Call TypeScript Method from jquery in angular 2

From Dev

Can't call model class's method from Component.html in angular2

From Dev

Angular 2 How to call a component method from index.html(script)?

From Dev

Call super method from Xcore operation

From Java

How to call super method from grandchild class?

From Dev

jruby call method from super java class

From

Call an overridden method from super class in typescript

From Dev

How to call angular method in html?

From Dev

How to call base class method from super class method

From Dev

Angular2: call component method from javascript function

From Dev

Angular 2 call method of one child from many

From

How to call component method from service? (angular2)

From Dev

Call angular2 method from javascript function

From Dev

Angular2 modal call method in parent from the child

From Dev

How to call get method from a class in Angular 2

From Dev

How to call super method?

From Java

How to call a subclass method from super's associated class

From Java

How to call super class method correctly from Mockito Junit

From Java

Java: How to call super method from inner in-place class

From Java

How to call a super method (ie: toString()) from outside a derived class

From Dev

Call super in module-defined method from inheriting class

From Dev

How to call outer class' super method from inner class in Kotlin?

From Dev

TS - Cannot call a public method within super() from the children

From Dev

Java Reflection: GetDeclaredFields() method call in inherited class from super class

From Dev

Call a method that returns html from an action method

From Dev

How to call a method of super class from parent class. How to call the same method from interface?

From Dev

angular2 - infinite loop when i call method from a Angular 2 class inside template

Related Related

  1. 1

    call Angular 2 component method from html event

  2. 2

    Call a component method from HTML in Angular2

  3. 3

    Call TypeScript Method from jquery in angular 2

  4. 4

    Can't call model class's method from Component.html in angular2

  5. 5

    Angular 2 How to call a component method from index.html(script)?

  6. 6

    Call super method from Xcore operation

  7. 7

    How to call super method from grandchild class?

  8. 8

    jruby call method from super java class

  9. 9

    Call an overridden method from super class in typescript

  10. 10

    How to call angular method in html?

  11. 11

    How to call base class method from super class method

  12. 12

    Angular2: call component method from javascript function

  13. 13

    Angular 2 call method of one child from many

  14. 14

    How to call component method from service? (angular2)

  15. 15

    Call angular2 method from javascript function

  16. 16

    Angular2 modal call method in parent from the child

  17. 17

    How to call get method from a class in Angular 2

  18. 18

    How to call super method?

  19. 19

    How to call a subclass method from super's associated class

  20. 20

    How to call super class method correctly from Mockito Junit

  21. 21

    Java: How to call super method from inner in-place class

  22. 22

    How to call a super method (ie: toString()) from outside a derived class

  23. 23

    Call super in module-defined method from inheriting class

  24. 24

    How to call outer class' super method from inner class in Kotlin?

  25. 25

    TS - Cannot call a public method within super() from the children

  26. 26

    Java Reflection: GetDeclaredFields() method call in inherited class from super class

  27. 27

    Call a method that returns html from an action method

  28. 28

    How to call a method of super class from parent class. How to call the same method from interface?

  29. 29

    angular2 - infinite loop when i call method from a Angular 2 class inside template

HotTag

Archive