The directive stops functioning properly following the minification process

Here is a directive that I am working on:

var tonicswitch = angular.module('tonicswitch', []).directive('multiSelectTonics', function(){
    return {
        restrict: 'E',
        scope: {
            items: '=',
            default: '=',
            leftTitle: '@',
            rightTitle: '@'
        },
        templateUrl: "views/tonicswitch.html",
        link: function(scope)   {
            scope.switchItem = function(item)   {
                var index = scope.default.indexOf(item);
                if(index == -1) {
                    console.log("Add tonic");
                    scope.default.push(item);
                } else {
                    console.log("Remove tonic");
                    scope.default.splice(index, 1);
                }
            }
        }
    };
})

tonicswitch.directive('switchtonic', function() {
    return {
        restrict: 'E',
        scope: {
            value: '='
        },
        template: '<div>{{value}}</div>'
    };
});

and here is the corresponding HTML code:

<style>
    .switchBox .entBox {
        overflow:auto;
        height:500px; 
        width:350px;
        border:1px solid black;
        float:left;
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        -o-user-select: none;
        user-select: none;
        padding: 10px;
    }
    .switchBox .entBox div:hover {
        background-color: #00FF03;
    }
    .switchBox .eBox2.entBox div:hover {
        background-color: #FF0007;
    }

    switchtonic {
        display: block;
        margin-top: 5px;
    }

    switchtonic:first-child {
        margin-top: 0;
    }
</style>

<label>
    <table>
        <tr>
            <th>{{leftTitle}}</th>
            <th>{{rightTitle}}</th>
        </tr>
        <tr class="switchBox">
            <td>
                <div class="entBox eBox1">
                    <switchtonic ng-repeat="(key, value) in items" ng-if="default.indexOf(key) == -1" value="value.getName()" ng-click="switchItem(key)"></switchtonic>
                </div>
            </td>
            <td>
                <div class="entBox eBox2">
                    <switchtonic ng-repeat="(key, value) in items" ng-if="default.indexOf(key) > -1" value="value.getName()" ng-click="switchItem(key)"></switchtonic>
                </div>
            </td>
        </tr>
    </table>
</label>

In my app.js file, I have included the directives in my module like this:

angular
  .module('Gins', [
    'ngAnimate',
    'ngAria',
    'ngCookies',
    'ngMessages',
    'ngResource',
    'ngRoute',
    'ngSanitize',
    'ngTouch',
    'parse-angular',
    'parse-angular.enhance',
    'ngDialog',
    'typeswitch',
    'tonicswitch'
  ])

I am using the directive in my HTML as shown below:

<multi-select default="selectedTypesNL" items="listOfAllNLTypes" left-title="All Types" right-title="Picked Types"></multi-select>

These are the variables in my controller:

$scope.selectedTypesNL = [];
$scope.listOfAllNLTypes = {};

When I receive my items, I do the following:

for(var indexAllTypes = 0; indexAllTypes < $scope.types.length; indexAllTypes++){
    $scope.listOfAllNLTypes[$scope.types[indexAllTypes].getType()] = $scope.types[indexAllTypes];
}

Everything works fine when I run grunt serve. However, when I run grunt build, the directive shows the table but does not repeat anything. The table remains empty. There seems to be an issue during the minification process. I do not see any errors, but disabling minifying solves the problem. Any ideas why this isn't working after minifying?

Answer №1

It's quite peculiar, but I found that disabling the htmlmin feature in my grunt file's build task resolved all issues.

Answer №2

After taking the advice of arjabbar to change the default keyword, I made the adjustment and now all functions properly, even with htmlmin activated.

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

The passage of time becomes distorted after a few hours of using setInterval

I created a simple digital clock using JavaScript to show the time on a TV screen. However, after several hours of running, I noticed that the displayed time gets off by a few seconds (around 30 or more). Below is the code snippet I used: getTime() { ...

Seeking assistance with my basic JavaScript/jQuery programming

I have a navigation menu link with an ID #navigation li a and a description with a class .menu-description. I would like to update the class from .menu-description to .menu-descriptionnew whenever a user hovers over #navigation li a. Here is my current jQ ...

<a href> click here to append a new query parameter to the existing ones

Is there a way to create a link that will add a query parameter to the current URL instead of replacing all existing ones? Here's what I'm looking for: If the current URL in the browser is example.com/index.html, clicking on it should lead to ...

Node.js route error: no script MIME types allowed with 'X-Content-Type: nosniff' header present

I'm facing an issue where my css and js files do not load on the second route, but they work perfectly fine on the first route. Could someone explain why this discrepancy occurs? // ********************** INDEX PAGE ******************************* ...

Error in Typescript: A computed property name must be one of the types 'string', 'number', 'symbol', or 'any'

Here is the current code I am working with: interface sizes { [key: string]: Partial<CSSStyleDeclaration>[]; } export const useStyleBlocks = ( resolution = 'large', blocks = [{}] ): Partial<CSSStyleDeclaration>[] => { cons ...

Ways to extract specific data from a Json response

Currently, I am engaged in a school project that involves manipulating json data from the Google Geocoding API. I am facing a dilemma on how to properly store the "formatted_address" (as shown below) from the API response so that I can utilize this inform ...

Socket connection in Vue not activating

I've been experimenting with incorporating Vue.js and sockets together, but I'm encountering an issue where my Vue application isn't receiving socket events. Despite following online tutorials, the example provided doesn't seem to work ...

Simply tap on any part of the row to select the checkbox and bring attention to it?

Is there a way to make rows in a table selectable by clicking anywhere on the row? I have a script that displays checkboxes next to each result from a MySQL database, but I want users to be able to click anywhere on the row to select it and highlight the e ...

The React application functions smoothly when executed using react-scripts start, but encounters an "Unexpected SyntaxError: Unexpected Token: <" error upon building

My goal is to deploy my portfolio site using an express server and react-scripts build. Everything works perfectly fine when I run react-scripts start. However, when I try to serve up the build index.js, I encounter the following errors: 2.8b4a0c83.chunk.j ...

What are the best practices for implementing jquery owlCarousel within an Angular 4 component?

I've included my 'carousel.js' file like this: $('#owl-carousel-1').owlCarousel({...}); and in carousel.component.html, I have: <div id="owl-carousel-1" class="owl-carousel owl-theme center-owl-nav home- carousel">....< ...

Selecting options on hover, either A or B at the least

I need a jQuery selector to handle an 'either' scenario. Specifically, I have a dropdown menu and want it to stay open when the user hovers over either of two elements. Either when they hover over the button or when they leave the popped-out men ...

Recursive instruction malfunctioning

I'm currently trying to develop a custom recursion directive, but unfortunately it's not functioning as expected. I have followed the instructions outlined here: Recursion in Angular directives For reference, you can view the fiddle here: http ...

The JavaScript audio is not working for the first three clicks, but starts playing smoothly from the fourth click onwards. What could be causing this issue?

$(".btn").click(function(event){ playSound(event.target.id); }); function playSound(name){ $("." + name).click(function() { new Audio("sounds/" + name + ".mp3").play(); ...

Implementing asynchronous loading of an image onto a webpage using JavaScript

Is it possible to asynchronously load an image specified in the src attribute of an HTML image tag? I am trying to invoke a Java class using an image src tag, but I want this to happen asynchronously without affecting the current functionality of the web ...

Could it be that my DataTable sourced through ajax is not parsing as expected?

When troubleshooting, the first step is usually to identify the error at hand... DataTables alert: tableid=myTable - Encountered unknown parameter 'Name' for row 0, column 0. For further assistance regarding this issue, please refer to http://da ...

Accessing Properties in React.js: A Guide

<Element id="1" onClick={this.runFunction(???)}/> When the onClick event is triggered, I want to execute a different function with the key value "1" as an argument. How can I make this happen? Thank you. ...

Guide on transforming the bars icon in the navbar to a cross (xmark) in responsive view with Font Awesome in VueJS

Looking to swap out the 'bars' icon in the navbar for an 'xmark' icon upon clicking, without resorting to triple navbar in responsive view</a>. The complete code snippet (combining HTML, CSS, and JavaScript) is available below: & ...

Running a Python script through a Javascript event

I'm looking to enhance my webpage by implementing a feature where users can generate a personalized QR code with the click of a button. My current setup involves a Python script that creates the QR code image and saves it as a .png file. I want to int ...

Toggling jQuery to show or hide content depending on the selector

I am looking to implement a jQuery-based animation and here is the code I have so far: >items=document.querySelectorAll("#customers td span"); [<span alt=​" 02,Counter,11,2013-04-06 14:​59:​16">​ 02​</span>​, <span>​11 ...

Using jQuery, apply the ng-style attribute to an element once it has been created

Using CodeMirror in combination with Angular has been a helpful tool. The CodeMirror element is dynamically created by invoking the following code: myCodeMirror = CodeMirror.fromTextArea( document.getElementById("paper"), opts ); This specific line of co ...