0

I am using angular + requirejs, and want to make it work with typescript. How can i write this script in typescript?

HomeController1.js

define(['controllers/controllers'],
    function (controllers) {
        controllers.controller('HomeController',
            ['$window',
            '$scope',
    function (
        $window,
        $scope) {

        $scope.showSubRouting = true;

        }

    ]);
});

Controllers1.js

define(['angular'], function (angular) {
    'use strict';
    return angular.module('controllers', []);
});

I tried this :

HomeController2.ts

 import controllers = require("controllers/controllers");

     class HomeController {

        showSubRouting: boolean = false
        constructor() {

        }


    }

Controllers2.ts

import angular = require("angular");

angular.module("controllers", []);

but controller's definition is missing in HomeController2.js (define(['controllers/controllers'])

HomeController2.js

define(["require", "exports"], function (require, exports) {
        var HomeController = (function () {
            function HomeController() {
                this.showSubRouting = false;
            }
            return HomeController;
        })();
    });

Do you guys know what I am doing wrong?

Thanks in advance

1 Answer 1

0

Controllers2.ts

You need to export what you want to import elsewhere. So:

import angular = require("angular");

export var controllerModule = angular.module("controllers", []);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.