TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

Import modules with AMD

Open nadav2511 opened this issue 11 years ago • 1 comments

I've started a Web Application project in VS15. I have the following as my root component in TS file:

/// <reference path="../typings/angular2/angular2.d.ts" />
import {Component, View, bootstrap, formDirectives} from 'angular2/angular2';
import comp = require('comp');
@Component({
    selector: 'my-app'
})
@View({
        directives: [formDirectives, comp.DisplayComponent],
    templateUrl: 'mainForm.html'
})
class AppComponent {
    firstName: string;
    lastName: string;
    hello(): void {
        alert("hello2, " + this.firstName + " " + this.lastName);
    }
    constructor() {
        this.firstName = "John";
        this.lastName = "Doe";
    }
}
bootstrap(AppComponent); 

I also have another TS file as another component that I'd like to use:

/// <reference path="../typings/angular2/angular2.d.ts" />
import {Component, View, bootstrap} from 'angular2/angular2';

@Component({
    selector: 'dispComp'
})
@View({
    templateUrl: 'sp.html'
})
export class DisplayComponent {
    myName: string;
    constructor() {
        this.myName = 'Alice';
    }

}

My my problem is with the import of comp - in the code above I don't have a compilation error, but when I run it I get a 404 error in the browser for not finding "http://localhost:60553/comp", which is correct, since in my wwwroot the correct path is js/comp.js.

when I try to change my code into import comp = require('js/comp.js'), I get a compilation error (cannot find module js/comp.js), and the TS won't translate into JS.

What am I doing wrong here?

nadav2511 avatar Aug 18 '15 13:08 nadav2511

what module loader are you using? how are your input file folder structure look like?

mhegazy avatar Aug 18 '15 19:08 mhegazy