Using ng-class with the Angular Material chips component

Is there a way to add backlight to chips with an 'active' flag based on my key value type using

ng-class="{activeTag: $chip.active}"
? I tried implementing it but it doesn't seem to work. How can I incorporate this ng-class into dynamically created md-chips?

View

<md-chips class="custom-chips selected" ng-model="tags" ng-class="{activeTag: $chip.active}" readonly="true">
  <md-chip-template style="cursor: pointer;" >
    <a ui-sref="">
      <strong>{{$chip.id}}</strong>
      <em>({{$chip.name}})</em>
    </a>
  </md-chip-template>
</md-chips>

Controller

controller('ChipsController', function($scope) {
    $scope.tags = [
      {
        id: 1,
        name: 'Pop',
        active: false
      },
      {
        id: 2,
        name: 'Rock',
        active: true
      },
      {
        id: 3,
        name: 'Reggie',
        active: false
      }
  ];

});

css

.activeTag md-chip{
  background: rgba(85, 107, 47, 0.66) !important;
  color: white !important; 
}

Experience the Code on Plunker

Answer №1

The issue may arise from your attempt to utilize $chip with the md-chips element instead of the correct target. Remember, the container is different from the repeater. The items inside your template are what will be repeated.

Although I lack expertise in MD components, it seems you are trying to access $chip at a level beyond its reach

Answer №2

Give this method a try. Update your CSS to target just .activetag and include ng-class in md-chip-template

CSS:

.activeTag {
  background: rgba(85, 107, 47, 0.66) !important;
  color: white !important; 
}

html :

<md-chips class="custom-chips selected" ng-model="tags" readonly="true">
  <md-chip-template ng-class="{activeTag: $chip.active}" style="cursor: pointer;" >
    <a ui-sref="">
      <strong>{{$chip.id}}</strong>
      <em>({{$chip.name}})</em>
    </a>
  </md-chip-template>
</md-chips>

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

Error found in the HTML tag data when viewing the page source for an issue

I am displaying some data from my express to ejs in HTML tag format. It appears correctly on the ejs template page and the web page. However, when I check the page source, the HTML tags are encoded and displayed as unescaped characters. Is there a solution ...

Animate the menu as you scroll

I am attempting to create a jQuery top menu that adjusts its height based on the window scroll position. Using $(selector).css("height", "value") works fine, but when I try to animate it, it doesn't behave correctly. Here is my code. Thank you for you ...

Converting Epoch 0 to current date with the help of moment.js

Looking for a way to convert an epoch date to a Date object? Here is the code snippet I used: let convertedDate = moment(maintenance.actualEndDate * 1000).format('DD/MMM/YYYY hh:mm'); Keep in mind that if 'maintenance.actualEndDate' h ...

Discovering an item within an array of objects using the find method in Ajax

Within my backend PHP code, I iteratively define the following: foreach ( $data as $res ){ $approved[ ] = [ 'id' => $count, 'title' => "some title" ]; $count++;$title=... ) This eventually leads to the creation ...

Tips for including HTML tags within a string using node.js, express, and ejs

Currently, I am utilizing Node.js with Express and EJS for my project. My goal is to pass HTML tags within a string to the browser in the following manner: listRequests.forEach(function(key) { messages.push("You have a message from <b>" + key.us ...

Managing post requests within the express.js framework

I need assistance utilizing the value provided in a form within Node.js. Here is an example: index.html : <!DOCTYPE html> <html lang="en"> <head> </head> <body> <div align="middle" > <!--Ethernet ...

`How can I dynamically hide a collapsible Bootstrap navbar with a click event in a React.js application?`

Hey there! I've managed to create a collapsible navbar with Bootstrap 5 that is working smoothly, but now I want it to automatically close when the user clicks on a link. Is there a way to achieve this in React? Thanks in advance! React.JS navbar : ...

Create an attribute with no assigned value

I am currently working on developing one of my initial Angular templates. In the process of looping through an array, I would like to incorporate the required attribute. Each iteration of the array is structured as follows: { label: 'Last Nam ...

Next.js app experiencing issues with Chakra UI not transitioning to dark mode

After attempting to incorporate Chakra UI into my Next.js application, I carefully followed every step outlined in their documentation: Despite setting the initialColorMode to "dark" for the ColorModeScript prop, it seems that the dark mode is not being a ...

Integrate an input field with a copy function similar to the GitHub clone view

Can anyone help me create a view with a tooltip similar to the one on Github? You can see the example here: https://i.sstatic.net/iBSof.png I attempted to use CSS but couldn't quite replicate the exact UI. Here is my current CSS code: [tooltip] { ...

Incorporating a javascript library or plugin into Vue.js code

Hey there, I recently came across the really cool component called vue-social-sharing. It's my first time using a library like this and I'm a bit confused on how to set it up properly. I've installed it through NPM, but when it comes to the ...

What is the best way to handle my JavaScript libraries in Grunt - Bower or NPM?

After diving into Grunt, I've come to realize how amazing it can be. However, I have one concern when it comes to managing Javascript libraries. Currently, my workflow involves searching for each library online and placing them in a js/libs folder. Th ...

Angular offers a range of search filters for optimizing search results

The system currently has 3 search fields: 1. Name.... 2. Subject.... 3.Price.... Each of these filters works independently - when searching by name, only results matching that name are displayed; similarly for subject and price. However, the challeng ...

Activate event starting from parent and ascending through child nodes

When I have a table inside a <div class="timely"></div>, and within that table is a <th class="prev"><i>previous</i></th>, Chrome developer tools show an event listener on the <th>. However, Firefox developer tools ...

Using the setInterval function in conjunction with the remoteCommand to create a

I am attempting to create a remote command that calls a bean function and updates a progress bar every 2 seconds until cancelled. The remote command looks like this: <p:remoteCommand id="usedCall" name="queryUsed" onco ...

Enhancing the Appearance of Google Line Charts

Incorporating Google line charts into my upcoming web project has been a goal of mine. I aim to customize them in the style displayed in this image and display dates between months. Can anyone provide guidance on how to achieve this, if it is feasible? ...

Incomplete input values can be retrieved using AngularJS Ngblur

I am curious as to why the ngblur directive is not capturing the complete value of a text input. Currently, I am utilizing the easyautocomplete plugin to search through a JSON file. Upon finding a match, the plugin displays several suggestions that can be ...

Typescript's way of mocking fetch for testing purposes

I have a query regarding the following code snippet: import useCountry from './useCountry'; import { renderHook } from '@testing-library/react-hooks'; import { enableFetchMocks } from 'jest-fetch-mock'; enableFetchMocks(); i ...

Leverage JQuery's Range Slider for Real-Time CSS Value Updates

Trying to dynamically update CSS properties such as minmax(20vw), grid-gap, and height using individual range sliders: #wrapper { grid-template-columns: repeat(auto-fit, minmax(20vw, 1fr)); grid-gap: 20px; } #item { height: 150px; } Utilizing CSS grid a ...

Tips for utilizing props in a Vue component

When trying to incorporate a prop into a computed value, I encounter the following error: [Vue warn]: Error in render: "TypeError: Cannot read property 'length' of undefined" found in ---> at src/cmps/space-details/space-imgs.vue at src/pa ...