Angular JS and TypeScript - Issue: ng:areq Invalid Argument "Argument 'XXXXXX' is not a function, received undefined"

Encountering a specific error mentioned in the title.

I organized models and controllers into distinct files saved under models and controllers folders respectively.

Upon trying to establish a connection between them, I received an error stating "ng:areq Bad Argument "Argument 'rightPaneCtrl' is not a function, got undefined".

What could be potentially incorrect with my code?

index.html↓

<html ng-app="rightpaneMVC" data-framework="typescript">
<head>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="//code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">
    <!--<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.1.min.js"></script>
    <script src="//code.jquery.com/ui/1.9.2/jquery-ui.min.js"></script>
    <script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>-->
    <style>
        .item_list {
            display: flex;
            flex-direction: row;
            padding-left: 0;
        }

            .item_list > li {
                list-style-type: none;
                cursor: pointer;
                border: 1px solid black;
                padding: 0.3rem;
                width: 100px;
                margin-right: 0.2rem;
            }
    </style>

    <link rel="stylesheet" href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css">
</head>
<body>

    <div id="tab-category" ng-controller="rightPaneCtrl">
        <!--<ul>
            <li ng-repeat="tab in vm.tabs track by $index" ng-click="vm.handleTabClick(tab,$index)">
                <a href="#{{ tab.tabID }}">{{ tab.name }}{{ tab.tabID }}</a>
                <span ng:class="{true:'ui-icon ui-icon-circle-close ui-closable-tab', false:''}[$index!=0]"></span>
            </li>
        </ul>-->
        <hr />
        <tabset ng-init="startActive = true">
            <tab ng-repeat="tab in vm.tabs track by $index" active="startActive">
                <tab-heading ng-switch="tab.isClosable">
                    <div ng-switch-when=true>
                        {{ tab.name }} <a ng-click="vm.handleTabClick($index)" href=''><i class="icon-remove"></i></a>
                    </div>
                    <div ng-switch-when=false>
                        {{ tab.name }}
                    </div>
                </tab-heading>
                <ul class="item_list" ng-switch="tab.categoryTypeString">

                    <li ng-switch-when="DAI" ng-repeat="item in tab.items" ng-click="vm.handleItemClick(item)">
                        <img ng-src="{{item.thumbnailPath}}"><br />
                        <p align="center">{{ item.categoryName }}</p>
                    </li>
                    <li ng-switch-when="CHU" ng-repeat="item in tab.items" ng-click="vm.handleItemClick(item)">
                        <img ng-src="{{item.thumbnailPath}}"><br />
                        <p align="center">{{ item.categoryName }}</p>
                    </li>
                    <li ng-switch-default ng-repeat="item in tab.items">
                        <img ng-src="{{item.thumbnailPath}}"><br />
                        <p align="center">{{ item.categoryName }}</p>
                    </li>
                </ul>
            </tab>
        </tabset>


        <!--<div ng-repeat="tab in vm.tabs track by $index" id="{{ tab.tabID }}">

                <ul class="item_list" ng-switch="tab.categoryTypeString">
                    <li ng-switch-when="DAI" ng-repeat="item in tab.items" ng-click="vm.handleItemClick(item)"> {{ item.categoryName }}</li>
                    <li ng-switch-when="CHU" ng-repeat="item in tab.items" ng-click="vm.handleItemClick(item)"> {{ item.categoryName }}</li>
                    <li ng-switch-default ng-repeat="item in tab.items"> {{ item.categoryName }}</li>
                </ul>
            </div>-->
    </div>

    <script src="//code.angularjs.org/1.4.1/angular.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.4.0/ui-bootstrap-tpls.min.js"></script>
    <script src="Application.js"></script>
    <script src="controllers/RightPaneCtrl.js"></script>
</body>
</html>

Application.ts↓

module rightpane {

    'use strict';

    angular.module('rightpaneMVC', ['ui.bootstrap']);
    angular.module('rightpaneMVC').controller('rightPaneCtrl', RightPaneCtrl);
} 

RightPaneCtrl.ts↓

 module rightpane {

        'use strict';

        export class RightPaneCtrl {        

            public static $inject = ['$scope', '$http'];        

            private mModel = new RightPaneTabList;        

            public constructor(

                private $scope: any,
                private $http: ng.IHttpService) {

                $scope.vm = this;        
            }        

            public get tabs(): Tab[] {
                return this.mModel.tabs;
            }        

            handleItemClick(aItem: Item): void {
                console.log('Item clicked');
                this.mModel.addCategory(aItem);
            }        

            handleTabClick(tabIndex: number): void {
                console.log('Tab clicked');
                this.mModel.tabs.splice(tabIndex, 1);
            }        
        }        
    } 

Directory Structure↓

root
    |-index.html
    |-controllers
        |-RightPaneCtrl.ts

Answer №1

After making some progress with the previous solution, new issues have surfaced and the original poster (OP) has created this plunker:

http://plnkr.co/edit/WLH1GgLlpE7nek1poWnA?p=preview

The error message displayed is as follows:

TypeError: rightpane.RightPaneTabList is not a function at new RightPaneCtrl (RightPaneCtrl.js:14) ...

An updated and partially functioning version now exists. The issue arose due to missing components in the browser... To address this problem, we need to include the following documents in the correct order:

enums/ECategoryType.js models/Item.js models/Tab.js models/RightPaneTabList.js controllers/RightPaneCtrl.js Application.js

All of these scripts must be appended to the page code properly:

<script src="enums/ECategoryType.js"></script>
<script src="models/Item.js"></script>
<script src="models/Tab.js"></script>
<script src="models/RightPaneTabList.js"></script>
<script src="controllers/RightPaneCtrl.js"></script>
<script src="Application.js"></script> 

(Some images may be missing, but the app should still function)

Answer №2

Two key issues are at play here. You can see an example demonstrating the changes below (a simplified version for demonstration purposes)

Firstly, when using a class, it must already be loaded in order to work properly. This means that the order of the scripts needs to be adjusted:

// We need to ensure JS recognizes our Ctrl
<script src="controllers/RightPaneCtrl.js"></script>
<script src="Application.js"></script>
// If loaded here, it would be too late
// <script src="controllers/RightPaneCtrl.js"></script>

Additionally, because our Controller has a module or namespace:

module rightpane {        
    export class RightPaneCtrl {
    ...

We must reference it by its full name:

angular.module('rightpaneMVC')
    // Instead of this
    // .controller('rightPaneCtrl', RightPaneCtrl);
    // We need to use this
    .controller('rightPaneCtrl', rightpane.RightPaneCtrl);

You can verify the changes here

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

Element sticking on scroll down and sticking on scroll up movements

I am currently working on a sticky sidebar that catches and stays fixed at a certain scroll point using JavaScript. However, I am facing an issue where I need the sidebar to catch when scrolling back up and not go further than its initial starting point. ...

Unable to set selected property in React Material-UI menu item

One issue I'm facing is setting the selected prop using react mui menu item. In a multiple select menu list, there's a field called allValues that, when clicked, should toggle the selection of all menu items. The code for this functionality looks ...

What steps should I take to create a slider using my image gallery?

I have a unique photo gallery setup that I'm struggling with: As I keep adding photos, the cards in my gallery get smaller and smaller! What I really want is to show only 4 photos at a time and hide the rest, creating a sliding effect. I attempted ad ...

Using JavaScript functions within PHP is not supported

Currently, I am utilizing Laravel for my backend operations. Within my setup, there exists a JavaScript function called StartJob() that facilitates Google crawling. In the scenario where I input a keyword, which is then cross-referenced with the database, ...

Sharing data between view and controller in Laravel: a guide

Currently, I am developing a product cart feature that includes subtotal and grand total values displayed within <span> tags. My goal is to pass the grand total value to the controller for further processing. However, I encountered an issue where the ...

"Utilizing a function from an external file within the Main App function - a step-by-step guide

I am currently learning React.js and I have come across a challenge that I'm unable to solve easily. I am trying to use functions instead of classes in my code, but I am struggling with using these functions as components within my Main function. Here ...

Jasmine Timeout issue

Currently, I am in the process of writing a karma unit test script. Everything seems to be going smoothly, but unfortunately, I am encountering an error: Chrome 39.0.2171 (Windows 7) Unit: common.services.PartialUpdater Should be loaded with all dependenc ...

Guide on validating an Australian phone number with the HTML pattern

When it comes to PHP, I have found it quite simple to validate Australian phone numbers from input using PHP Regex. Here is the regex pattern I am currently using: /^\({0,1}((0|\+61)(2|4|3|7|8)){0,1}\){0,1}(\ |-){0,1}[0-9]{2}(\ | ...

Problem with Custom MUI fields not detecting value change

I want to make custom form components so I don't have to update each item individually if I want to change the style. The ReportSelect component doesn't update the value when a menu item is selected, and the ReportTextField only works for the fir ...

What steps should I take to make sure that the types of React props are accurately assigned?

Dealing with large datasets in a component can be challenging, but I have found a solution by creating a Proxy wrapper around arrays for repeated operations such as sorting. I am looking to ensure that when the data prop is passed into my component as an ...

Efficiently running multiple PHP pages with just one simple click

Below is the code fragment that I currently have: <html> <script type="text/javascript"> function Run() {var a=["ONE" ,"TWO" ,"THREE", "FOUR", "FIVE"]; window.location.href = "index.php?w1=" +a;} </script> <body> <input type="b ...

Backend framework

Currently, I am in the process of developing a robust web application that heavily relies on JavaScript and jQuery, with ajax functionality included. Additionally, there will be a database in place, managed using mySQL with several tables. I'm undeci ...

Adjust the x and y coordinates of the canvas renderer

Manipulating the dimensions of the canvas renderer in Three.js is straightforward: renderer = new THREE.CanvasRenderer(); renderer.setSize( 500, 300 ); However, adjusting the position of the object along the x and y axes seems more challenging. I've ...

Ways to verify whether a vue instance is empty within a .vue file by utilizing the v-if directive

I am facing an issue with a for-loop in Vue that iterates through a media object using v-for to check if it contains any images. Everything is working correctly, but I want to display a div below the loop saying "There is no media" when the object is empty ...

Showcasing top performers via JavaScript tabs

I have two tabs on my webpage: "Overall Leaderboard" and "Weekly Leaderboard". Each tab displays a leaderboard with different scores. When I click on the "Overall Leaderboard" tab, it shows a leaderboard with specific scores. Now, my question is how can ...

Using Node.js and Express to retrieve data from a MySQL database and update a table

My .ejs file contains a form that sends data to a MySQL database and then displays two tables with the retrieved data on the same page. However, I am facing an issue where the tables do not refresh after submitting the form, requiring me to restart the ser ...

Troubleshooting video streaming loading issues caused by 404 errors in URL paths with videojs

I've been successfully using the video.js library to stream live video. Everything was going well until after a while, the URL started throwing a 404 error during streaming, causing the entire player to get stuck on loading. Now I'm looking for a ...

Struggling with obtaining react-modal in my React Component

Greetings to all React developers out there, especially the newbies like me. I am currently facing an issue with implementing react-modal in my React Component based on this example here. Unfortunately, I have encountered several errors that are proving di ...

Customized validation message in Angular Formly with live data

I'm currently working with angular-formly and attempting to create a validation that checks if the user input falls within a dynamically set range of two numbers. I thought the simplest way to achieve this was by using a few variables, and while the v ...

Steps for adjusting the matMenuTriggerFor area so it only triggers when hovering over the arrow

Hello there! I'm currently working on adjusting the trigger area for opening the next menu panel. Right now, the next menu panel opens whenever I hover over either the title or the arrow. However, my goal is to have the menu open only when I hover ove ...