Using Angular 2 to invoke the super method from an HTML file

After successfully inheriting a class, I am facing an issue in calling the super method from the template. The error message that I currently receive 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 { }

The template code looks like this:

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

I have also tried using $super and $parent but without any success. Currently, the only solution that works is to create the method in Dimarts and then call super from there.

Any suggestions on how to resolve this issue?

Answer №1

super is a feature of ES6 syntax that is limited to the method where it is used. When a class Foo extends another class Bar, the keyword super refers to Bar in the constructor and static methods of Foo, and Bar.prototype in instance methods.

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

This code will be transpiled as:

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));

Using super.presentModal() in a template goes against the idea of class inheritance and prototype chains.

If presentModal is not defined in the child class, it should be inherited from the parent class like this:

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Obtain data based on the type of property

When examining the provided code snippet, I aim to filter properties based on their data type: interface Wrapper<T> { x: T; } interface WrapperOpt<T> { y?: T; } interface A { a1: number; a2: Wrapper<number>; a3: Wra ...

Develop a routing system for a complex Angular application with multiple modules

As a newcomer to Angular, I am exploring a multi-module structure within my Angular app. Each module such as login, user, and report contains one or two components. My current focus is on implementing routing, with the requirement that the login page must ...

Avoiding DOM replacement when using ngFor asynchronously with AngularFire2 in Angular 2

In my angular2 application with angularfire2, I am dealing with an async list of messages. <message *ngFor="let message of messages | async" [message]="message"></message> Whenever the list gets updated, all elements in the ngFor loop appear ...

problem with angular navigation bar

Currently, I am working on a project using angular and encountering an issue with the navigation bar. I have attached two screenshots for reference. The first screenshot displays the layout before logging in, and the second one showcases the layout after ...

Customizing the choices for an ActionSheet on Ionic 2 on the fly

After making a GET request, I receive JSON data containing an array of options with id, style, and name for each element. I need to dynamically populate the options in my ActionSheet within my Ionic 2 app based on this API response. The ActionSheet is fu ...

Encountering "Runtime Compiler Not Loaded" Error in Angular 8

Is there a way to dynamically generate lazy-loaded routes? I've been using the import syntax like this: loadChildren: () => import(`./pages/${module.moduleName}/${module.moduleName}.module`).then(m => m[childModuleName]), and it works with JIT, ...

Dealing with CORS and multiple headers

After setting up CORS for my web api project and deploying it to local IIS, I encountered an issue when trying to call a controller method from Angular. The error message displayed was as follows: SEC7128: Multiple Access-Control-Allow-Origin headers ar ...

There was an issue with the computed property: "Parsing error - '}' was expected

While trying to set a computed property in my Vue component using TypeScript to specify a return type, I encountered an error from eslint. Even though the application functions correctly, the error persists. I have experimented with removing the typing an ...

Create a simulated API in Angular by utilizing JasonPlaceholder to retrieve information upon clicking a button

I am currently developing a dummy API using jsonplaceholder. I have managed to retrieve all posts after clicking a button, but now I want to display the user ID and title by default on page load. Additionally, when clicking on a post's title, I would ...

Intellisense for dispatch types in Redux Toolkit

After following the documentation for redux toolkit with typescript, I implemented my own useDispatch hook as shown below export const useAppDispatch = () => useDispatch<AppDispatch>() and used it in components like this const dispatch = useAppDi ...

What advantages does incorporating observables into Angular 5 HTTP requests offer?

I have been struggling with understanding how to use httpclient in angular 5. As a newcomer to Angular, I am currently following the official angular tutorial but find myself lacking knowledge about observables, promises, pipes, and more. At the moment, I ...

Protractor experiencing difficulty recognizing Angular functionality

Recently, I made the switch to using Protractor for running end-to-end tests on my Angular application. However, the e2e tests have suddenly started failing because Protractor is unable to detect Angular on the website. I raised this issue in their GitHub ...

Active Class in Angular Dynamic Carousel

I recently set up a dynamic carousel that pulls images directly from a node backend. While everything seems to be in working order, I've run into an issue where all the images are being displayed at once instead of sliding through one at a time. This ...

Is it possible for me to create a union type that connects parameters and responses in a cohesive manner

I'm interested in creating a custom type that functions can use to indicate to callers that an input parameter of a specific type corresponds to a certain output type. For instance, consider the following scenario: type ResponseMap = { requestPath: ...

Synchronized scrolling and equal height for multiple divs

Looking to create a system similar to GitHub's conflict resolver for my project. I have multiple versions represented by values in columns, and I want to be able to select different values from each column to create a new solution. It's important ...

experiencing an excessive amount of re-renders after transferring data to a distinct component

At the moment, I have implemented this logic to display data based on the results of a graphql query, and it is working well: const contacts = () => { const { loading, error, data } = useUsersQuery({ variables: { where: { id: 1 }, ...

Avoiding an endless spiral on a setter in JavaScript/TypeScript

Implementing TypeScript, I've been working on setting up a concept called a "trigger" : an object that includes both a checker function (which returns a Boolean) and a behavior function capable of performing various tasks. My aim is to execute the che ...

Implementing Login using Google in a Nativescript iOS application: A step-by-step guide

I've been working on implementing Google's ID provider login in Nativescript using the nativescript-social-login plugin. While it works smoothly on Android, I've hit a roadblock with iOS. Following the instructions from the plugin creator, ...

Attempting to sort data with AngularJS

I'm currently working on implementing 'order by' functionality in my Angular app. Here's what I've attempted: <div *ngFor = "let movie of webService.movie_list | async | orderBy:'Year'"> However, when testing it ...

What is the correct way to implement async RedisJSON functions?

I'm currently facing an issue with properly typing the redis node package. For instance, let's consider the basic code snippet for a simple JSON.GET operation. import * as redis from 'redis'; const client = redis.createClient(); async f ...