Assess the equation twice using angular measurement

I am attempting to assess an expression that is originating from one component and being passed into another component.

Here is the code snippet:

Parent.component.ts

parentData: any= {
    name: 'xyz',
    url: '/test?testid={{element["TestId"]}}'
};

Parent.component.html

<child [data]="parentData"></child>

child.component.ts

@Component({ 
selector:'child'
...
})
export class ChildComponent {
    @Input() data: any;
}

child.component.html

<td mat-cell *matCellDef="let element">
    <a href="{{data.url}}">{{element["TestName"]}}</a>
</td>

The href attribute is currently evaluating as

/test?testid={{element["TestId"]}}
, when it should be evaluating to /test?testid=123

element["TestId"] needs to be evaluated within the child scope.

I came across this helpful link but I am unsure of how to implement it in my specific scenario.

EDIT: I have added a link for a similar example on StackBlitz. My goal is to create a generic ChildComponent, allowing the parent to determine which column to evaluate for element["TestId"]. Please disregard any unnecessary edits, as I am still learning to improve the way I present my questions.

Answer №1

You have the option to create a function based on that particular property

parentGridData = {
  ...
  url: element => `http://www.google.com/searchText=${element["name"]}`
};

Afterwards, provide an appropriate parameter:

<a href="{{gridData?.url(element)}}">

Just ensure that the function you create is not overly complex.

Take a look at the Forked Stackblitz

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

Spacing between hidden checkboxes and their labels

I've customized some checkboxes to resemble a select dropdown by hiding the input and using only the label as the visible element. However, I'm struggling to add margin between the elements, which seems to work only when the checkbox is visible. ...

Developing a search feature within a MEAN stack application

I'm a beginner in the world of MEAN stack applications and I'm curious about how to incorporate search functionality into my application. While I've done some research on the topic, most suggestions point towards using elastic search. Do you ...

Steps for pulling information from the database and presenting it in a text box for users to edit

I'm struggling with a webpage that should allow users to update data from the database, but for some reason, the data is not displaying in the textbox. How can I make it show up correctly? Currently, on my webpage, users have to manually input all th ...

An HTML table featuring rows and columns that can be adjusted in size separately from the content within each cell

Looking to create an HTML table where the columns and rows can be sized independently of the cell content? If a row or column isn't large enough to display all the content, it should simply overflow behind the cell. A solution was found that worked in ...

Stop flex items from expanding larger than their sibling elements

Is there a way to prevent a flex item from growing bigger than its siblings? Check out the example on CodeSandbox: LINK Here is the sample code: <div class='wrapper'> <div class='box one'></div> <div class ...

display a dual-column list using ngFor in Angular

I encountered a situation where I needed to display data from an object response in 2 columns. The catch is that the number of items in the data can vary, with odd and even numbers. To illustrate, let's assume I have 5 data items to display using 2 co ...

Angular to always show loading spinner on page load

Utilizing my Angular project with the Ant Design NG Zorro loading spin. I encountered an issue where the loading spin is continuously active on my Angular page. Does anyone know the correct way to implement this loading spinner? Thanks View the example o ...

Why is my Javascript XMLHttpRequest onreadystatechanged event not triggering?

I am facing an issue with my html file and a .txt file stored in the same directory on a webserver. In the html file, I have the following code: <html> <head> <script> window.onload = function() { receiveMessage(); } function recei ...

What impact do Angular Signals have on RXJS Observables and how does this influence change detection within the framework?

As I transition to Signals in my Angular App, I am encountering challenges in identifying best practices and dealing with unexpected behaviors. Here is a snippet of my code which includes a userService and two Components: export class UserService { priva ...

"Composing perfect sentences: The art of incorporating quotes

I am attempting to include text with quotes in a DIV, like so: "All is well that ends well" The text is generated dynamically and I'm using a JavaScript font replacement plugin (CUFON) to add quotes around the text. Sometimes, the ending quote drops ...

The Keyup Filter in the FromEvent function is malfunctioning and not behaving as anticipated

I have created a simple search function for my app using the FromEvent KeyUp and debounceTime features as shown in the code below: <input matInput #inputSearch> @ViewChild('inputSearch', { static: false }) input: ElementRef; fromEvent(th ...

Exploring the World of Print CSS, Embracing Bootstrap, and Master

In continuation of my previous query, I am facing an issue with setting up a filemaker foreach loop to display a group of images along with their names and IDs, accompanied by checkboxes. Upon checking the relevant checkboxes, the corresponding images are ...

Iterate through the MongoDB database array by using the @foreach loop in an Express application

Hey there, I've got a database that I can view using HTML and Express layout. I believe @each and {{}} are JavaScript syntax. {{posts[0].detail}} <----------------This is working However, I'm looking to display all the contents of each pos ...

Attempting to design a form that will trigger a print dialog box displaying all the information entered in the form

I am currently working on developing a form that will allow users to input information such as Name, Age, Gender, Hobbies, Contact details, and Photo in order to create a resume. My goal is to build a simple local HTML-based application that generates a RE ...

Error: AJAX encountered an unexpected token

An error message has appeared stating: Uncaught SyntaxError: Unexpected token : This error relates to the following line of code: data: userCoupon: $('#couponCode').val(), Here is the script in question: $(function() { $("#signInButton2"). ...

Error Encountered: Nested textarea not supported in HTML

Below is the code I am working with. The issue lies with the <textarea>. In my form, there is a textarea. When I insert another <textarea> within the ckeditor value (HTML), the inner textarea ends up closing the parent textarea. Is there a sol ...

Can the href values within <a> tags be altered based on the existing href value?

I am currently in the process of integrating Video JS and Colorbox. My objective is to utilize jQuery to easily modify all href values that contain ".mp4" by replacing it with ".html". This modification will enable the existing code to function smoothly, ...

Issues with jQuery animate.css functionality specifically occurring on Firefox browser

As a beginner in jQuery, I have been exploring different animations and recently came across an issue with Firefox compatibility. I discovered the animate.css library, and decided to incorporate its animations into text captions on a slider using the Soli ...

What is the method in PHP to send an HTML file along with a value in response to a POST request?

I have a PHP file where I want to include a dropdown list and submit button. The dropdown list should display filenames for the user to choose from. Once the user selects a filename from the dropdown list and clicks the submit button, the PHP file should r ...

Confirm your identity without using a Single Sign-On (SSO) system

My current situation involves a PHP-based website where users login using credentials stored in a database. Additionally, we have another SPA website with .NET CORE as the API layer. Unfortunately, we do not have the option of utilizing a central authent ...