The object referred to by v.context.$implicit.(PropertyName) does not have a callable method

In Angular6, I want to implement dynamic permissions. My goal is to fetch a list of menu items from the database:

<li *ngFor="let op of optionList">
    <!-- <fa-icon [icon]="op.icon"></fa-icon>  -->
    <label (click)='op.routeFunctionName()'>{{op.optionName}}</label>
</li>

The function op.routeFunctionName() is intended for routing purposes.

This is an example of how routing should be implemented:

GoRoleManager() {
     this.router.navigate(['panel/dashboard/'+this.userName+'/role']);
}

However, when clicking on the menu item, I encounter the following error:

ERROR TypeError: _v.context.$implicit.routeFunctionName is not a function

What could be causing this problem? How can it be resolved?

Answer №1

It seems like you mistakenly saved JavaScript code in the variable routeFunctionName and attempted to call it as a function. In reality, it's just plain text. If you really want to execute it, you can use eval, but this is considered not recommended.

Update: Please refer to the comments for additional information.

If you wish to invoke a function using a string variable, you should format it as shown below:

<label (click)='this[op.routeFunctionName]()'>{{op.optionName}}</label>

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

Tips for uploading information to a web service

Issue Description:- I am attempting to access web services from a different domain (i.e. Systems are not locally connected) and encountering the following error: "Failed to load : Response for preflight is invalid (redirect)" var username = "<a href= ...

Creating an interactive table with the power of FPDF and PHP

I have developed a unique Invoice System that allows users to customize the number of headings and fields using FPDF in conjunction with PHP. Subsequently, I can input the heading names and field values into HTML input fields. However, I am encountering a ...

What is the most efficient way to assign multiple keys and values to an object in JavaScript using a function?

I possess an object var bar = { "propA" : "valueX", "propB" : "valueY", "propC" : "valueZ" }; and I am looking for a method to create a function that can receive multiple key and value pairs all at once. My current approach is as follows: f ...

Encountered a 400 error when trying to install Angular CLI on Windows 10 through a proxy server

Recently delving into Angular, I encountered the need to install Angular CLI on my Windows 10 PC behind a proxy server. Running Node v12.13.1 and npm v6.12.1, I followed the steps of copying the script address value from Proxy settings and updating the con ...

Having trouble making md-data-table directives function properly

I'm struggling to incorporate the md-data-table library from https://github.com/daniel-nagy/md-data-table into my webpage. Despite loading the library in Chrome, none of the directives seem to be working. Here's a snippet of my code - can anyone ...

Is it possible to receive live updates from a MySQL database on a webpage using node.js and socket.io?

I've been following a tutorial that teaches how to receive real-time updates from a MySQL database using Node.js and Socket.io. Check it out here: Everything seems to work fine on the webpage. I can see updates in real-time when I open the page on tw ...

Error in NextJS Middleware Server: Invalid attempt to export a nullable value for "TextDecoderStream"

I've recently created a straightforward Next.js application using bun (version 1.0.4, bun create next-app), incorporating app routing with Next.js version 13.5.4 and a designated source directory. My goal was to implement a middleware that restricts a ...

Transforming JSON data into XML using Angular 7

It turns out the xml2js npm package I was using doesn't support converting JSON to XML, which is exactly what I need for my API that communicates with an application only accepting XML format. In my service file shipment.service.ts import { Injecta ...

Create a PDF document using the combined HTML content

I am facing an issue with generating a PDF from HTML content. My goal is to convert all the content within a specific div into a PDF. I have tested out a few converters, but they only seem to convert HTML files. I do not want to convert the entire HTML fi ...

Gradient transition effect changing background color from bottom to top

I am facing an issue where I have a block and I want the background color to animate from bottom to top on hover. Can you please help me identify what is causing this problem? Your assistance is greatly appreciated. .right-block--wrapper { backgroun ...

Converting URL-esque information to JSON using JavaScript

Does anyone have a solution for converting an array of URL-like data into JSON format? For example, how can we convert the array ["a.b.c.d", "a.c.e.f", "a.b.c.g"] into the following JSON structure: items:{ text: "a", items:[ { ...

Learn the process of importing data types from the Firebase Admin Node.js SDK

I am currently facing a challenge with importing the DecodedIDToken type from the https://firebase.google.com/docs/reference/admin/node/firebase-admin.auth.decodedidtoken. I need this type to be able to assign it to the value in the .then() callback when v ...

Pass data back and forth between app.js (node) and javascript (main.js)

I am facing a challenge in sending and retrieving data (username) between app.js and main.js. In my setup, I have a node app.js that calls index.html which then triggers the main.js function called "clicked". Below is the code snippets for each file: app. ...

JavaScript timekeepers and Ajax polling/scheduling

After looking into various methods like Comet and Long-Polling, I'm searching for a simpler way to push basic ajax updates to the browser. I've come across the idea of using Javascript timers to make Ajax calls at specific intervals. Is this app ...

Empty screen appears when "npm run serve" command is executed following the build process

I am currently utilizing Material-ui. Following the project build with npm run build, I encounter a blank page when running npm run serve. I attempted to set homepage: "./" in the package.json as suggested here, however, it still displays a blank ...

Tips for creating animated arc fills using CSS

Can we gradually fill the color of a CSS semi-circle in a counterclockwise direction, similar to a progress bar? Here is the code for the semi-circle: https://jsfiddle.net/sonymax46/wqfovdjh/7/. .cc{ background-color: transparent; overflow: hidd ...

Creating PDF from HTML in Angular 2: A Step-by-Step Guide

Is there a way to create a download button within my angular2 project that allows users to save HTML div content as a PDF file? Below is the HTML content that needs to be saved as a PDF: <div id="obrz"> <br><br> <p class="float-r ...

Trouble altering an attribute using jquery

Hey there, I'm struggling with changing the attribute for an id and can't quite pinpoint where I'm going wrong. It's not making things easier that I'm pretty new to this whole thing as well. I've created a function to ensure ...

Navigating between pages in ReactJS using Material UI can be made simple and efficient with the

While working on creating a drawer for my dashboard using material-Ui, I encountered an issue with navigating between pages Let me start by sharing my app.js file where the product route is defined: <Provider store={store}> <BrowserRouter> ...

Creating an interactive animation of bouncing balls within an HTML5 canvas using JavaScript

function refBalls(){ var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); var circles = [{x:40,y:100,r:20,color:'black',vx:5,vy:10}] function draw(){ ctx.beginPath(); ctx.arc(circles[0].x, circles[0].y, circles[0].r, ...