Issue with minifying Angular controller functions

Upon running the Angular controller provided below, I encounter an error stating "TypeError: t.getDealers is not a function". This issue arises due to the minification of the Javascript code. Unfortunately, I am unsure of the steps required to rectify this error.

myApp.controller('DLOController', ['$scope', 'DLOFactory',
    function ($scope, DLOFactory) {

        $scope.init = function () {
            $scope.searchType = [{ id: 1, name: "Search by Postcode" }, { id: 2, name: "Search by State" }, { id: 3, name: "Search by Dealer" }];
            $scope.selectedSearchType = 1;
            $scope.selectedState = -1;
            $scope.postcode = "";
            $scope.dealerName = "";
            $scope.states = [];
            $scope.dealers = [];

            getStates(2);
            getDealers(2);

        }

        function getStates(categoryType) {
            DLOFactory.getStates(categoryType)
                .success(function (val) {
                    $scope.states = val;
                })
            .error(function (error) {
                // REVISIT: LOG ERROR HERE.
            });
        }

        function getDealers(categoryType) {
            DLOFactory.getDealers(categoryType)
                .success(function (val) {
                    $scope.dealers = val;
                    console.log($scope.dealers);
                })
            .error(function (error) {
                // REVISIT: LOG ERROR HERE.
            });
        }

    }
]);

This is the factory being utilized:

myApp.factory('DLOFactory', ['$http', function ($http) {

    var stateList = [];
    var dealerList = [];

    return {
        getStates: function (categoryType) {
            return $http({
                method: 'GET',
                url: '/Addresses/GetStateList',
                params: { categoryType: categoryType }
            })
            .success(function (responseData) {
                stateList.push(responseData);
            });
        },
        getStateList: function () {
            return stateList;
        },
        setStateList: function (sl) {
            stateList = sl;
        }
    }

    return {
        getDealers: function (categoryType) {
            return $http({
                method: 'GET',
                url: '/Websites/GetDealers',
                params: { categoryType: categoryType }
            })
            .success(function (responseData) {
                dealerList.push(responseData);
            });
        },
        getDealerList: function () {
            return dealerList;
        },
        setDealerList: function (dl) {
            dealerList = dl;
        }

    }
}]);

The minified equivalent of the code appears as follows:

myApp.controller("DLOController",["$scope","DLOFactory",function(n,t){function i(i){t.getStates(i).success(function(t){n.states=t}).error(function(){})}function r(i){t.getDealers(i).success(function(t){n.dealers=t;console.log(n.dealers)}).error(function(){})}n.init=function(){n.searchType=[{id:1,name:"Search by Postcode"},{id:2,name:"Search by State"},{id:3,name:"Search by Dealer"}];n.selectedSearchType=1;n.selectedState=-1;n.postcode="";n.dealerName="";n.states=[];n.dealers=[];i(2);r(2)}}]);

Answer №1

Since there are two return statements in the factory function, the second one will not be executed. It is recommended to combine both return statements and test it out.

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

Updating properties of nested objects in React JS

When I call this function using the onChange property of an input field, the first console.log displays the changed value accurately. However, the second one does not show the expected result. Despite attempting to deep copy newDisplayedAssignment and mak ...

Utilize the Express Validator for Date and Time validation

I need help with validating a DateTime string similar to the code provided below { "data": { "start": "2018-05-12 08:00:00" } } Is it possible to use both isISO8601() and match(regex) functions to validate date & time in the 'sta ...

There was a rendering error: "Type Error: Unable to access the 'PAY_TYPE' property of null"

I am attempting to retrieve the PAY_TYPE value from the callback_details object by using JSON.parse() function to convert a string into an object. However, I keep encountering an error related to the question's title. Here is my code snippet: <td ...

`Cannot Get jQuery ScrollTop Function to Work for 2nd Element`

Having trouble with an issue. Let me explain. I implemented a scrollTop Jquery on page load that scrolls down after a delay to prompt user action. However, I'm facing a problem where another scrollTop doesn't work after clicking buttons "#b3,#b3 ...

Tips for consistently utilizing a 'set-method' to modify the attributes of an object employed as ng-model

In my controller, I initialize: $scope.foo = new Foo('test'); // foo.property is now 'test' Then in the view, I have: <input type="text" ng-model="foo.property" /> However, I prefer not to directly change foo.property. I woul ...

Retrieve the latest entry from a JSON file containing epoch timestamps

Currently, I am in the process of developing an app using angularjs. In my json data, I have timestamps and corresponding values like below: { "dps": { "1455719820": 0, "1455720150": 0, "1455720480": 0, "1455720810": 0, " ...

Iterating through parent data using ng-repeat and nesting another ng-repeat within it

I have an array of objects containing a players array. My goal is to display this information in a table row, with the nested array's values in the middle of the row. However, I am encountering an issue where the last column comes up blank and is labe ...

Can you explain the significance of verbosity in a nodemon setup?

Can someone explain the verbose setting in my nodemon configuration and what impact it has on the project? { "verbose": true, "watch": "./server" } I have checked the readme file for nodemon, but it doesn't provide any information on this specif ...

Focus event in IE does not always work as expected after an ajax request is

Our current focus is on supporting IE8 exclusively. An ajax call retrieves data from the server, replaces the HTML in a container div with the response, and then attempts to focus on an element within the response. However, there seems to be inconsistenci ...

Ways to incorporate a unique debounce technique where the function is only executed every nth time

const _debounce = (num, fn) => { //implementation goes here } const originalFunction = () => { console.log('fired') } const _callFunc = () => _debounce(2, originalFunction) _callFunc() //The originalFunction does not run _callFun ...

Removing an item from a Redis list using Node.js

Recently, I encountered a challenge involving managing a list in Redis using Node.js. I successfully stored a list with the following code snippet: client.rpush(['room_'+room, data.customClient], function(err, reply) { client.lrange(&ap ...

Checkbox radio buttons with mandatory selection

I'm facing a challenge with radio buttons in my form. While checkboxes could easily solve this issue, the customer specifically requested radio buttons. Here is the relevant section of the form: <label> <span>I Agree*</span> ...

What is the best way to delay a method in vue.js?

In the tab element called competences, there is an input field with the reference search. <ul class="nav nav-tabs" id="myTab" role="tablist"> <li class="nav-item"> <a @click="competencesTabClick" aria-controls="Company" aria-sel ...

Issue with Bootstrap 5 Carousel not transitioning between slides

I am trying to add a carousel to my webpage, but it seems like it's not sliding and only displaying the first image. I've double-checked my code and everything else from Bootstrap works fine. Here's the snippet of code I'm using: < ...

Create a variable called `myUInt8Array` of type `UInt

How can I declare a function parameter of type UInt8Array in TypeScript? import * as fs from "fs"; fs.readFile(fileName, (err: string, data: UInt8Array) => { if (err) { return console.error(err); } ...

Creating a scrollable div with a fixed background using HTML

Attempting to create a full-screen image background with a scrollable div in its center, I crafted the following code: <!doctype html> <html> <head> <meta charset="utf-8"> <title>Bio</title> <link href="../css/layout ...

Troubleshooting: Issue with jQuery not recognizing this.id

Hey everyone, check out my code snippet below: $ (".input_check").change (function (){ if ($ (this).is (':checked')) { console.log(this.id + 'is checked') } else { console.log(this.id + &apo ...

Retrieve the title of an item stored within a list

Let's say I have an array filled with objects - exactly 10 of them, each with unique names. var upgrades = [ tree = {price: 20, rate:0.5, owned:0}, irr = {price: 80, rate:1, owned:0}, press = {price: 150, rate:2, owned:0}, cracker = {price: 400, rate ...

Endless loop in React Native with an array of objects using the useEffect hook

For the current project I am working on, I am facing the challenge of retrieving selected items from a Flatlist and passing them to the parent component. To tackle this issue, I have initialized a local state as follows: const [myState, setMyState] = useS ...

Using specific delimiters in Vue.js components when integrating with Django and Vue-loader

While working on my Django + Vue.js v3 app, I came across a helpful tool called vue3-sfc-loader. This allows me to easily render .vue files using Django, giving me the best of both worlds. The current setup allows Django to successfully render the .vue fil ...