需要Angular和TypeScript

时间:2015-11-28 19:16:47

标签: angularjs requirejs typescript

我正在使用angular + requirejs,并且想要使用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', []);
});

我试过了:

HomeController2.ts

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

     class HomeController {

        showSubRouting: boolean = false
        constructor() {

        }


    }

Controllers2.ts

import angular = require("angular");

angular.module("controllers", []);
HomeController2.js中缺少

控制器的定义 (define(['controllers/controllers']

HomeController2.js

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

你们知道我做错了什么吗?

提前致谢

1 个答案:

答案 0 :(得分:0)

  

Controllers2.ts

您需要导出要在其他位置导入的内容。所以:

import angular = require("angular");

export var controllerModule = angular.module("controllers", []);