After compilation, any variables declared within a module remain undefined

I have declared the following files

app.types.ts

/// <reference path="../../typings/tsd.d.ts"/>
module App{
    export var Module =     "website";
    //---------------Controller Base Types---------------
    export interface IScope extends ng.IScope {
        events: Controller;
    }
    export class Controller{
        protected scope: IScope;
        static id       : string;
        constructor($scope: IScope,controllerId:  string){
            this.scope        =     $scope;
            this.scope.events =     this;
            Controller.id                =      controllerId;
        }
    }
}

app.ts

    /// /// <reference path="app.types.ts"/>
    module App {
    "use strict";
    var app = angular.module(Module, [
        // Angular modules
        'ngMessages','ngAnimate','ngTouch','ngAria','ngSanitize',
        // Custom modules
        'ui.router','ui.bootstrap','ui.bootstrap.tpls'
        // 3rd Party Modules
    ]);
}

The code compiles to Js without errors but the variable Module is undefined across the file.

I also tried using App.Module but still the variable was undefined

Update : I have check the app.types.js is inserted in the html before app.js. There generated Js files seem to be incorrect.

//App.js
(function(){/// <reference path="app.types.ts"/>
var App;
(function (App) {
    "use strict";
    var app = angular.module(App.Module, [
        // Angular modules
        'ngMessages', 'ngAnimate', 'ngTouch', 'ngAria', 'ngSanitize',
        // Custom modules
        'ui.router', 'ui.bootstrap', 'ui.bootstrap.tpls'
    ]);
})(App || (App = {}));
}());

//App.types.js
(function(){/// <reference path="../../typings/tsd.d.ts"/>
var App;
(function (App) {
    App.Module = "website";
    var Controller = (function () {
        function Controller($scope, controllerId) {
            this.scope = $scope;
            this.scope.events = this;
            Controller.id = controllerId;
     }
     return Controller;
    })();
    App.Controller = Controller;
 })(App || (App = {}));
}());

Answer №1

It is advisable to include the following in your code:

/// <reference path="relative/path/to/app.types.ts"/>

In order to ensure the correct loading order of scripts, make sure to add this line to your app.ts file. It seems like currently app.types.js is being loaded after app.js.

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

Utilizing Jquery-Menu-Aim to assign values to child scopes

Currently, I am in the process of developing a directive for jQuery-menu-aim. While my current implementation is functioning as intended, I can't help but feel that finding and setting values on the child scope seems like a workaround. You can view m ...

Include form data into an array of objects within an Angular data source

I am struggling to add the edited form data from edit-customers-dialog.ts into an array of objects in my datasource. The form.data.value is returning correctly, but I'm facing issues with inserting it properly into the array. As a beginner in Angular ...

Angular 2 has upgraded its Controller functionality by replacing it with Component

I find it a bit challenging to distinguish between Component and Controller. How was the Controller replaced by component in Angular 2? I came across this description of a component: In Angular, a Component is a distinct type of directive that utilizes a s ...

Cypress: Importing line in commands.ts is triggering errors

After adding imports to the commands.ts file, running tests results in errors. However, in commands.ts: import 'cypress-localstorage-commands'; /* eslint-disable */ declare namespace Cypress { interface Chainable<Subject = any> { c ...

Why is the `node-config` configuration undefined within a TypeScript Jest environment?

I have a TypeScript module that is functional in both development and production environments. It utilizes https://github.com/lorenwest/node-config. When I attempt to import it into Jest for testing purposes, I encounter an error suggesting that the config ...

The $http.get request is successful only when the page is initially loaded for the first

Imagine this scenario: a user navigates to http://localhost:3000/all, and sees a list of all users displayed on the page. Everything looks good so far. However, upon refreshing the page, all content disappears and only raw JSON output from the server is sh ...

Angular: Modifying the parent scope from a child component

Hey there! So I'm a beginner in this whole programming thing, but I'm currently working on a small application where I can add and update items with details using Ionic, Cordova, and AngularJS. However, I've hit a roadblock with the followin ...

Transmitting image data (blob) from the frontend to the backend using Next.js and tRPC (T3 stack)

I'm currently facing a challenge in sending a leaflet map image from the backend to the frontend using the leaflet-simple-map-screenshoter library for capturing the image. The library returns a blob, which I need to transmit back to the backend and sa ...

Enhancing JavaScript with TypeScript: implementing functional mixins

I'm in the process of creating functional mixins using TypeScript. Below is the code I have written so far: const flying = (o: object) => { let isFlying = false; return Object.assign({}, o, { fly() { isFlying = true; return thi ...

I'm curious if there is an eslint rule specifically designed to identify and flag any unnecessary spaces between a block comment and the function or

Can anyone help me find a solution to prevent the following issue: /** * This is a comment */ function foo() { ... } I need it to be corrected and formatted like this: /** * This is a comment */ function foo() { ... } ...

Unusual AngularJS Service Function Styling

I previously inquired about a similar issue, but unfortunately did not receive any correct answers. The query pertains to the service function in AngularJS. Interestingly, when I defined an AngularJS service using the service function in an unconventional ...

How can I reference a Bootstrap icon in the buttonImage attribute of a jQuery datepicker?

How can I customize the jQuery datepicker button image? I want to use the Bootstrap calendar icon as the button image for the jQuery datepicker. The icon image can be referenced in the HTML page like this: <i class=icon-calendar></i> When us ...

Customizing AxiosRequestConfig with Axios in TypeScript can greatly enhance the functionality and

Currently working with React and Axios. Lately, I've been experimenting with custom configurations in Axios as shown below: import $axios from 'helpers/axiosInstance' $axios.get('/customers', { handlerEnabled: false }) However, wh ...

Navigating the world of Typescript: mastering union types and handling diverse attributes

I am currently working on building a function that can accept two different types of input. type InputA = { name: string content: string color: string } type InputB = { name: string content: number } type Input = InputA | InputB As I try to impleme ...

I encountered an issue with Angular where it is throwing an error stating that the property 'catch' does not exist on the type 'Observable<Object>'

I have been working on an angular application that interacts with a python flask API. During development, I encountered the need to display results passed from the backend. To achieve this, I created an angular service. Below is the code for the angular s ...

Retrieve data from ngModel within a custom directive

I'm attempting to retrieve the value of ngModel from my input by utilizing a directive, sadly I'm having difficulty retrieving it. Take a look at my code: angular .module('myapp') .directive('infoVal', myExtractor); ...

Obtain the element created by a directive within the controller

I'm currently utilizing the wrapper located at: https://github.com/Yankovsky/nouislider-angular/blob/master/nouislider.js for the nouislider plugin. Within my controller, I aim to access the element that I've created in the template: <div ya ...

"Unspecified error in Angular" encountered when implementing Mobile Angular UI in conjunction with Angularfire

I am currently working on developing a mobile app using Mobile Angular UI and integrating it with a Firebase database. However, I keep encountering an error when trying to include Firebase: Uncaught ReferenceError: angular is not defined at angularfire.m ...

Time passed with altitude reference

I'm currently working on displaying the time elapsed in an angular.js application using angular-moment, moment, and moment-timezone. Everything is functioning correctly, but the displayed time is 6 hours ahead for individuals located in Spain due to t ...

Implementing dynamic image insertion on click using a knockout observable

I'm utilizing an API to retrieve images, and I need it to initially load 10 images. When a button is clicked, it should add another 10 images. This is how I set it up: Defining the observable for the image amount: public imageAmount: KnockoutObserva ...