Exciting Angular feature: Dynamic Titles

I am working with an <i> tag

 <i class="actionicon icon-star" [ngClass]="{'yellow' : data.isLiked}" (click)="Like(data)"
 aria-hidden="true" title="Liked"></i> 

In my current setup, if data.isLiked is true, the yellow class is applied. However, I also need to modify the 'title' value based on this condition.

If isLiked is true, then the title should change to Unlike; otherwise, it should be set as Like.

Answer №1

To dynamically bind your title attribute to angular, use the following syntax:

[title]=" data.isLiked ? 'Liked' : 'Unliked' "

For instance:

<i class="actionicon icon-star" [ngClass]="{'yellow' : data.isLiked}" (click)="Like(data)"
 aria-hidden="true" [title]=" data.isLiked ? 'Liked' : 'Unliked' "></i> 

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

Title positioned between two buttons in the header

I am trying to add two menu buttons in my header, but the Hamburger menu button is not aligning to the left as expected. Currently, it looks like this: https://i.stack.imgur.com/s5ptT.png Below is the code snippet I am using: <ion-header> <io ...

React Native Expo Launch disregards typescript errors

While using Expo with Typescript, I've noticed that when I run the app with expo start or potentially build it, TypeScript errors are being ignored. Although Visual Studio Code still flags these errors, I can still reload the App and run it on my pho ...

The Angular form remains invalid despite all form fields being valid

After spending hours on an Angular form validation project, I have encountered an issue that has been difficult to resolve. The form I created seems to be working fine based on a demo I shared, where it shows the form status as VALID. However, when running ...

Is Angular 11 Compatible with Internet Explorer 5?

Is there a way to make Angular 11 compatible with Internet Explorer 5? I am developing an angular solution for a client whose default browser is Internet Explorer running on version 5 (by default). Initially, I am not supposed to change any browser configu ...

When trying to run ionic serve, I encountered the following error: "[ERROR] ng has unexpectedly closed with an exit code of 127."

My attempt to launch an ionic app on my Mac has hit a roadblock. While running npm install for the dependencies, everything goes smoothly without any issues. However, when I try to run 'ionic serve' or 'ionic s', an error crops up: [ng] ...

Encountered an error of 'npm ERR! invalid semver' when attempting to release an npm package

npm ERR! code EBADSEMVER npm ERR! invalid semver: npm ERR! Check out the full log of this run here: I attempted to reinstall node and semver, but unfortunately it did not resolve the issue. ...

You are unable to compile a module in Visual Studio Code unless you provide the --module flag

I am facing an issue with my TypeScript code file that appears to be a common error, but I'm struggling to resolve it. This problem is new to me as I am still getting acquainted with Visual Studio Code. Cannot compile modules unless the '--modul ...

Guide to leveraging tanstack table v8 for sorting data within a specific date range

Received data from API: const abc = [ { date: '2023-12-8', value: 'mop' },{ date: '2023-10-8', value: 'qrs' } ] How can we create a date range using two input fields when the dates are in string forma ...

Implementing Ionic Native Player for Practical Applications

Looking for a way to incorporate a lightweight mp3 file into my Ionic App, I decided to utilize Native Audio from Ionic. Despite my best efforts, the solution did not function properly on the iOS emulator when called from /MyIonicApp/src/pages/home/home.ts ...

The necessity of segregating Angular packages and the rationale behind their importance

Recently, I embarked on the journey of building a brand new Angular 2 app. After conducting thorough research by reading articles and downloading free apps from GitHub, I noticed that all of them included the angular/common package along with other package ...

Angular directive utilizing model reference for improved functionality

In my Angular 15 project, I am facing an issue with obtaining a reference to the ngModel in a custom directive. The goal is to create a directive that trims the input value before validation and triggers a data changed event to update the model. While I ca ...

Encountering an issue when attempting to convert data to JSON in Angular 13, as the content type 'text/plain;charset=UTF-8' is not supported. This problem arises after sending data from

I've been attempting to submit a form using the following method: saveBuildcompany(): void { // @ts-ignore // @ts-ignore console.log(this.group?.value); let data2=this.group.value; let serializedForm = JSON.stringify(data2) ...

What are the steps to creating an Observable class?

I am working with a class that includes the following properties: export class Model { public id: number; public name: string; } Is there a way to make this class observable, so that changes in its properties can be listened to? I'm hoping fo ...

Is it possible to reset the attributes of a container's children using a renderer?

Within a container, there are dropdowns, multiple selects, and quantity selections. When a button is clicked, I aim to reset the state of the component. https://i.stack.imgur.com/TY5un.png <input #select type="checkbox" value="somevalue"/> The ...

Sharing data among components in Angular 6

I've set up 2 components and a service as outlined below: component-interaction.service.ts @Injectable() export class ComponentInteractionService { public dataSubject = new BehaviorSubject<string>("Test"); getTestData(): Observable<an ...

The valueChanges event of a Reactive Form is activated whenever options from a datalist are selected

Whenever a user types into the input field, I am making an API call to retrieve and display data in a datalist for autocompletion (typeahead). control.get('city').valueChanges.pipe( map((searchText) => searchText.trim().toLowerCase()), fi ...

Unable to Navigate with NativeScript

Having recently ventured into Angular and NativeScript, I am currently working on creating an app. While I have successfully built my first page, I am facing some challenges with routing to my signInComponent. This is the setup that I currently have: In a ...

find the element in cypress with multiple child elements

Looking for a way to target the first HTML element that contains more than 2 children. Another option is to access the children elements of the first parent element. <div class="market-template-2-columns"> <button type="button&q ...

Fetching an item from Local Storage in Angular 8

In my local storage, I have some data stored in a unique format. When I try to retrieve the data using localStorage.getItem('id');, it returns undefined. The issue lies in the way the data is stored within localStorage - it's structured as a ...

Converting HTML to an array using Angular

Is there a way to convert HTML into an array of entities? For example: 'hi <em>there</em>' => ['hi', '<em>', 'there', '</em>'] ...