Tips for integrating jQuery styling into Angular 2

Using the farbtastic color picker, I am trying to pass the color code from jQuery to the HTML element with the property [style.backgroundColor]="color" when a button is clicked.

HTML:

<button ion-col full clear id="color-picker-handler" (click)="initiateColorPicker()">Pick Color</button>
  <ion-row class="selectedColor">
  <div class="selectedcolorCircle ion-col" [style.backgroundColor]="color" >
     </div>
     <div class="selectcolor ion-col">
     </div>
  </ion-row>

TS file:

initiateColorPicker() {
      jQuery('.selectcolor').farbtastic(function(color) {
        console.log(color)});
      console.log('Clicked');
  }

CSS :

.selectedColor {
  padding: 15px;
  width: 100%;
  min-height: 200px;
  text-align: center;

  .selectedcolorCircle {
    width: 135px;
    height: 135px;
    border-radius: 50%;
    margin: 0 auto;

  }
}

Answer №1

Here is a helpful tip for you:

import { Component, ChangeDetectorRef } from '@angular/core';

@Component({
  (...)
})

export class MyComponent {
  constructor(private cdr:ChangeDetectorRef) {
  }

   startColorPicker() {
      jQuery('.selectcolor').farbtastic((color)=>{
        console.log(color)
        this.color=color;
        this.cdr.detectChanges();
      });

      console.log('Color Picker Initialized');
  }
}

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

Oops! An error occurred: plugin_not_installed cordova plugin Filepath along with File Chooser. Please make sure to install the required plugins

Currently, I am utilizing the FilePath and File Chooser Plugin to select an attachment and then convert it into base 64. To install Filepath, I used the following commands: npm install cordova-plugin-filepath npm install @ionic-native/file-path For File ...

Is it possible to personalize CSS properties using PHP sessions?

Currently, I am a beginner in PHP and enrolled in a technical school class to learn more about it. Our latest assignment involves using sessions to modify four CSS properties: body background-color, a:link color, a:hover color, and h1 color. The task inclu ...

Looking to implement a dual-column layout for posts on WordPress using Bootstrap

Creating an intranet website for a client which functions similar to a Facebook or Twitter feed. The layout includes three columns using Bootstrap's grid system. The first column serves as a navigation sidebar, while the other two columns should disp ...

JS Issue with Generating Content

Introduction( kind of :) ) Starting with the process of generating 5 coffee beans for each cup of coffee. The coffee class includes a strength attribute, and my goal is to visually distinguish the coffee beans which have a strength greater than the select ...

Integrating additional youngsters into the HTML DOM using Angular.js

I am working with a block of HTML that looks like this: <div id="parent"> <div id="child_1"></div> <div id="child_2"></div> <div id="child_3"></div> <div id="child_4"></div> </div> ...

What is the best way to ensure that my transitionend event is triggered?

I'm currently exploring the <progress> element and attempting to incorporate a CSS transition to achieve a smooth progress bar effect as its value increases. Despite my efforts, I can't seem to trigger JS after the transitionend event occur ...

Using jQuery to create dynamic CSS effects directly on the drop-down menu button

Seeking your kind assistance once again... I am attempting to design a navigation bar that displays the dropdown section upon hovering over the buttons AND shows a bottom border on the button that was last hovered over My code functions properly when I ...

Storing information from JSON into an object

I am encountering an issue regarding transferring data from JSON to an object. Although this solution is functional, it is not entirely satisfactory. Take a look at the service. Is there an improved method for handling data conversion from this JSON to an ...

IE causing issues with Wordpress Ajax Javascript functionality

I encountered an issue with my JQuery code that seems to work in Chrome and Firefox, but not in IE8 or on my phone. I double-checked the code and there were no additional commas present. The error in IE8 specifically points to... $(document).on('c ...

Using a numeral within a Font Awesome icon symbol to customize a label for a Google Maps marker

I have a Google Maps marker displayed below, applying a Font Awesome icon as the label/icon. However, I am unsure how to a.) change the color of the marker and b.) include a number inside the marker. Referencing this Stack Overflow post This is the code ...

PhoneGap: Upgrade HTML files for offline functionality

I am seeking to develop an app that offers basic information in a table format. Currently using PhoneGap, I have the necessary data and can input it into the HTML file. However, if there are any updates or changes to be made, do I need to hold off on pub ...

Component experiencing issues with service or @Input functionality

I have been struggling with importing a service inside a component and encountering an issue where the Input from the service does not render anything in the template. Let's take a look at my entity: export interface PageState { step: string; } e ...

Limiting input to specific characters is effective on Chrome, but unfortunately does not function on Firefox

This code snippet is designed to restrict user input to lowercase letters from a-z, numbers from 0-9, and the dash character "-". While it functions correctly in Chrome, it does not allow any input in Firefox. What could be causing this issue? $('#sl ...

Styling Angular Datatables with CSS

i have data on the front end https://i.stack.imgur.com/2xq7a.jpg i need all check marks to be displayed in green color. Below is the code snippet: $scope.dtColumnsCal= [ DTColumnBuilder.newColumn('name').withTitle('Name') ...

Exploring the power of ContentChildren and ViewChildren in AngularElements with Angular 6 - a deep dive into

I have been experimenting with the new AngularElements feature which you can learn more about at https://angular.io/guide/elements. Initially, my tests were successful, but everything came to a halt when I integrated @ContentChildren. It makes sense to me ...

How to Disable a Dynamically Generated <li> Element Using jQuery on Click Event

Script Query: Creating <li> Elements Dynamically echo '<div class="pagination"><ul>' . "\n"; // Previous Post Link. if ( get_previous_posts_link() ) { printf( '<li>%s</li>' . "\n", get_previ ...

I require a modification in the style of every anchor element found within a div containing the designated class

In a div with the class fview, there is a nested element called iNside which contains a span. Additionally, there are anchor elements within another span, ul li, and another div, among others. I want all anchor elements to have the same style. I tried app ...

Enhancing the background with curves for optimal viewing on mobile devices

I'm currently pondering if I should create the shapes manually or simply use a background image to achieve the desired effect on mobile view. https://i.sstatic.net/y99A8.png Any input or guidance on this matter would be greatly appreciated. As of n ...

What is the best method to update numerous low-resolution image sources with higher resolution images once they have finished loading?

I'm currently developing a website that implements a strategy of loading low-resolution images first, and then swapping them for high-resolution versions once they are fully loaded. By doing this, we aim to speed up the initial loading time by display ...

Numerals for Central Leaflet Marker

Is there a way to effectively center numbers inside markers? Here is the current situation: View Marker with Number How to Create a Marker return L.divIcon({ className: "green-icon", iconSize: [25, 41], iconAnchor: [10, 44], popupAn ...