5

I'm trying to import an external class (written in Typescript) into another Typescript class using requireJS. I used this syntax but I don't understand why I'm getting a syntax error with this import statement:

enter image description here

I have also tried using this instead:

import t = module("Controller/TestController");

And I'm also getting the same error.

The above import/require statement resides in appmod.ts. This is my file structure:

+Root
  +Scripts
    +app
      -main.ts
      -appmod.ts
      +Controller
        -TestController.ts

I have looked through the documentation, and this line looks perfectly fine to me. The file TestController.ts does exist in the path and the classes are prepended with export keyword.

What's wrong with this line?

This is how my TestController.ts look:

/// <reference path="../typings/angularjs/angular.d.ts" />

module testApp.Controller {
     export interface ITestScope extends ng.IScope {
         helloString:string;
     }

     export class TestController {

         public static $inject = [
            "$scope"
         ];


         constructor(private $scope: ITestScope) {
            this.$scope.helloString = "Hello!";
         }
     }

 }

I've used DefinitelyTyped's AngularJS definition in my TestController.js.

1 Answer 1

3

Your export statement needs to be at the root level in your file. Remove the redundant module http://m.youtube.com/watch?v=KDrWLMUY0R0&hd=1

I.e. Delete 'module testApp.Controller'

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks! Removing the module testApp.Controller does get the thing to work. But I'm still curious, why can't I use namespaces for my angularjs controllers and services with RequireJS?
Each file is a module in AMD/CommonJS world
You can still use them if you prefix module with export. I.e. 'export module' but it's wasted chars

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.