Having trouble with less.modifyVars not functioning properly in Visual Studio?

I attempted to dynamically change the LESS variable using HTML within an AngularJS function. The code worked fine on XAMPP with simple HTML and CSS, but when I transferred it to an enterprise app in Visual Studio, it stopped functioning properly. While the variables compiled and the function ran smoothly, the less.modifyVars did not work as expected, failing to update on the fly. Here is a snippet of my HTML structure:

<link rel="stylesheet/less" href="~/Content/brandnew.less">
<script>
var less = {
    logLevel: 0,
    env: "development"
};
</script>
<script src="~/Content/less.min.js"></script>

Within the body:

 <form ng-submit="changeLess()">
                Enter text and hit enter to change color:
                <input type="text" ng-model="text" name="text" />
                <input type="submit" id="submit" value="Submit" />
            </form>

This is the content of my less file:

@color: #f16e8d;
.custom-anchor-color {
    color: @color;
}

And here is my JavaScript function that seems to be causing issues specifically in Visual Studio:

$scope.changeLess = function() {
            if ($scope.text) {
                debugger;
                less.modifyVars({
                    color: $scope.text
                });
                console.log($scope.text + ' inside $scope.text')
            }
        }

The function itself logs correctly, yet the color variable fails to update. I even tried keeping it as 'color' (with or without quotations), but encountered the same issue.

Answer №1

The issue has been identified. The application was already processing the code in advance, resulting in no variables remaining in the LESS file as it had already been rendered. This capability is achievable in VS through the use of dotless. Below is an example of how this can be implemented:

<httpHandlers>
      <add path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler, dotless.Core" />
    </httpHandlers>

For more information, visit:

Answer №2

Give this a shot:

updateStyles({
  '@primary-color': $scope.value
});

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

Learning to dynamically access files from various folders and subfolders within webpack using JavaScript

I'm currently working on a project in VueJs using webpack. As part of this, I need to dynamically include config/routing files from specific folders. Here is an example of my folder structure: plugins |----Ecommerce |--------backend |--------frontend ...

Create a line break in Html5 to separate the "content" element from its associated class

To create a design using html and css to display numbers in an image counter related to a carousel, follow these steps: https://i.stack.imgur.com/OBAHd.png I'm encountering an issue where I need to add a line break in the "content" so that the .down ...

Error message: Parameters are not defined in the Next.js

Struggling to retrieve the endpoint from a specific page in my Next.js application using URL parameters. Despite being able to view the endpoint in the browser, it keeps returning as undefined. I attempted utilizing usePathname from next/navigation, which ...

Is there a way to simulate the parameters of a method callback from an external dependency in Nodejs

Imagine a scenario where I have the following structure: lib/modules/module1.js var m2 = require('module2'); module.exports = function(){ return { // ... get: function(cb){ m2.someMethod(params, function(error, ...

Why does the "revalidate" field in Incremental Static Regeneration keep refreshing without considering the specified delay?

I am currently referencing the guidance provided at: https://nextjs.org/docs/basic-features/data-fetching/incremental-static-regeneration. My intention when setting the revalidate: 60 * 10 parameter is: To have the content remain consistent for at least ...

What could be causing the JavaScript/jquery code in my Functions.php file to only function properly on the initial post that loads on my WordPress website?

Currently, I am in the process of developing a WordPress website where the content is refreshed weekly. This means that all posts, media, and files are removed from the WP environment every week and replaced with new content. One of the key components of ...

The standard jQuery Mobile CSS styling does not seem to be working across various browsers, extensive testing has been conducted

I'm currently experimenting with jQuery Mobile to enhance my skills, but I'm facing issues with applying the basic CSS styling. I have included the css link from the jQuery Mobile website and ensured that I am connected to the internet. However, ...

Retrieve information from an SQL database using user input in a Classic ASP form without the need to refresh the page

Currently, I am in the process of incorporating a new function into an existing Classic ASP system. This feature involves allowing users to scan a barcode that will automatically populate a text field within a form inside a bootstrap modal. The scanner has ...

Choosing between creating a class with a shared instance or not

I'm curious if my class is shared across instances: for example, I have a route that looks like this: /student/:id When this route triggers the controller (simplified version): module.exports = RecalculateStudents; const recalculateActiveStudent ...

Guide on adding a timestamp in an express js application

I attempted to add timestamps to all my requests by using morgan. Here is how I included it: if (process.env.NODE_ENV === 'development') { // Enable logger (morgan) app.use(morgan('common')); } After implementing this, the o ...

How can you enhance page speed by minimizing the amount of bindings in AngularJS?

Background I have a project that requires users to edit results displayed in a list. Current Approach At the moment, I am duplicating the <span> tag for displaying results and the hidden <input> tag for editing. This is done within the same ...

Is it possible to update the variable value in one controller from another controller after an http.get request has been made

I have encountered an issue with updating a variable from one controller to another using a service. Despite my efforts, the variable is not being updated. The goal is to have the variable $scope.names in controller 'select' update in controller ...

Ways to adjust the size or customize the appearance of a particular text in an option

I needed to adjust the font size of specific text within an option tag in my code snippet below. <select> <?php foreach($dataholder as $key=>$value): ?> <option value='<?php echo $value; ?>' ><?php echo ...

Issue encountered when utilizing ngResource in factory: unable to choose JSON index

ngResource in a factory is functioning properly, but unfortunately, it is only able to select the index of the JSON. However, it is also possible to bind the same variable $scope.resultItems. The console log appears as follows ...

A React child error has occurred in Next.js due to invalid objects being used

Within my project, I have integrated the latest version of next.js and encountered an issue where objects are not valid as a React.js child. https://i.stack.imgur.com/MCO7z.png The problem arises after importing the Head component from Next.js and implem ...

The issue arising from Firefox's handling of try/catch blocks in window.onerror is not adequately addressed

It appears that Firefox handles errors differently when they occur in the window.onerror event handler compared to other browsers. While IE, Chrome, and Safari behave as expected, Firefox seems to treat any error in this context as a critical exception, ev ...

adjust bootstrap column width to fill the container

https://i.stack.imgur.com/tCuL6.png I am hoping that this image will provide a visual aid for what I am trying to convey. My goal is to have the arrow and the boxes aligned in a row without any empty space on the right side. As you can see, the leftmost b ...

Ways to showcase HTML content in angular when receiving entities

Is there a way to properly display HTML characters using HTML entities? Take this scenario for example: Let's say we have the following string: $scope.myString = "&lt;analysis mode=&quot;baseball&quot; ftype=&quot;&quot; version ...

Executing a function upon the loading of a template in AngularJS

I have been searching through various responses here, but I haven't come across one that addresses my specific problem. Apologies if this has already been answered. I am a beginner in angular js and have recently begun working on angular routing. I am ...

Refreshing a Next.js page results in a 404 error

I've set up a Next.js page called page.js that can be accessed through the URL http://localhost:3000/page. However, I have a need to access this page through a different URL, namely http://localhost:3000/my-page. To achieve this, I decided to utilize ...