When typescript compiles it creates the define() function (for either requirejs or commonjs) based on the presence of either import or export. But notice that import and export work only on typescript modules not simple js files. You can do something like this
import myimportmodule = require("myimportmodule");
Where your import module was
export module myimportmodule
{
export class Test
{}
}
And you can't do something like this.
import angular = require("angular");
simply because angular.js is not a typescript module.
look at the code below
/**
* Created by Costa on 4/19/2014.
*/
///<reference path="../ts_references/reference.ts"/>
///<amd-dependency path="angular"/>
//register controllers
import ImportMainCtrl = require("controllers/import/importMainCtrl");
export module Controllers
{
var angular:ng.IAngularStatic = require("angular");
var ControllersAM:ng.IModule;
ControllersAM = angular.module('controllers', []);
ControllersAM.controller(ImportMainCtrl);
}
Notice this line?
///<amd-dependency path="angular"/>
it will add a dependency into the define function so the js file looks like this:
/**
* Created by Costa on 4/19/2014.
*/
///<reference path="../ts_references/reference.ts"/>
define(["require", "exports", "controllers/import/importMainCtrl", "angular"], function(require, exports, ImportMainCtrl) {
(function (Controllers) {
var angular = require("angular");
var ControllersAM;
ControllersAM = angular.module('controllers', []);
ControllersAM.controller(ImportMainCtrl);
})(exports.Controllers || (exports.Controllers = {}));
var Controllers = exports.Controllers;
});
//# sourceMappingURL=controllers.js.map
Thats why you need this
var angular:ng.IAngularStatic = require("angular");
To access angular functionality. Hope that helps. Edited---- Or you can do the following in either angular.d.ts or another .d.ts file if you really want to import it like this
declare module 'angular'{
export var angular:ng.IAngularStatic;
}
this will create an external module declaration with the var angular inside and export it.