Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/427.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在TypeScript中导入模块不会';行不通_Javascript_Typescript_Systemjs - Fatal编程技术网

Javascript 在TypeScript中导入模块不会';行不通

Javascript 在TypeScript中导入模块不会';行不通,javascript,typescript,systemjs,Javascript,Typescript,Systemjs,我有两个打字脚本文件, 第一个app.ts文件输入点 模块中的第二个mobiles.ts文件包含接口和类 模块系统CommonJS,设置了ECMAScript版本ES5 运行应用程序时,在浏览器中获取错误 ReferenceError:未定义require 在app.js:2 mobiles.ts文件的内容 export interface Device { model: string; company: string; displayInfo(): void; } e

我有两个打字脚本文件, 第一个app.ts文件输入点 模块中的第二个mobiles.ts文件包含接口和类 模块系统CommonJS,设置了ECMAScript版本ES5

运行应用程序时,在浏览器中获取错误

ReferenceError:未定义require 在app.js:2

mobiles.ts文件的内容

export interface Device {
    model: string;
    company: string;
    displayInfo(): void;
}

export class Smartphone implements Device {
    model: string;
    company: string;

    displayInfo(): void {
        console.log(`Smartphone. Model: ${this.model} - Company: ${this.company}`);
    }
}

export class Tablet implements Device {
    model: string;
    company: string;

    displayInfo(): void {
        console.log(`Tablet. Model: ${this.model} - Company: ${this.company}`);
    }
}
import {Smartphone} from "./mobiles";

window.onload = () => {
    let mi: Smartphone = new Smartphone();
    mi.company = "Xiaomi";
    mi.model = "RedMi 4 Pro";
    mi.displayInfo();
};
"use strict";
var Smartphone = (function () {
    function Smartphone() {
    }
    Smartphone.prototype.displayInfo = function () {
        console.log("Smartphone. Model: " + this.model + " - Company: " + this.company);
    };
    return Smartphone;
}());
exports.Smartphone = Smartphone;
var Tablet = (function () {
    function Tablet() {
    }
    Tablet.prototype.displayInfo = function () {
        console.log("Tablet. Model: " + this.model + " - Company: " + this.company);
    };
    return Tablet;
}());
exports.Tablet = Tablet;
//# sourceMappingURL=mobiles.js.map
"use strict";
var mobiles_1 = require("./mobiles"); //Error Get here
window.onload = function () {
    var mi = new mobiles_1.Smartphone();
    mi.company = "Xiaomi";
    mi.model = "RedMi 4 Pro";
    mi.displayInfo();
};
//# sourceMappingURL=app.js.map
文件app.ts的内容

export interface Device {
    model: string;
    company: string;
    displayInfo(): void;
}

export class Smartphone implements Device {
    model: string;
    company: string;

    displayInfo(): void {
        console.log(`Smartphone. Model: ${this.model} - Company: ${this.company}`);
    }
}

export class Tablet implements Device {
    model: string;
    company: string;

    displayInfo(): void {
        console.log(`Tablet. Model: ${this.model} - Company: ${this.company}`);
    }
}
import {Smartphone} from "./mobiles";

window.onload = () => {
    let mi: Smartphone = new Smartphone();
    mi.company = "Xiaomi";
    mi.model = "RedMi 4 Pro";
    mi.displayInfo();
};
"use strict";
var Smartphone = (function () {
    function Smartphone() {
    }
    Smartphone.prototype.displayInfo = function () {
        console.log("Smartphone. Model: " + this.model + " - Company: " + this.company);
    };
    return Smartphone;
}());
exports.Smartphone = Smartphone;
var Tablet = (function () {
    function Tablet() {
    }
    Tablet.prototype.displayInfo = function () {
        console.log("Tablet. Model: " + this.model + " - Company: " + this.company);
    };
    return Tablet;
}());
exports.Tablet = Tablet;
//# sourceMappingURL=mobiles.js.map
"use strict";
var mobiles_1 = require("./mobiles"); //Error Get here
window.onload = function () {
    var mi = new mobiles_1.Smartphone();
    mi.company = "Xiaomi";
    mi.model = "RedMi 4 Pro";
    mi.displayInfo();
};
//# sourceMappingURL=app.js.map
编译文件mobiles.js的内容后

export interface Device {
    model: string;
    company: string;
    displayInfo(): void;
}

export class Smartphone implements Device {
    model: string;
    company: string;

    displayInfo(): void {
        console.log(`Smartphone. Model: ${this.model} - Company: ${this.company}`);
    }
}

export class Tablet implements Device {
    model: string;
    company: string;

    displayInfo(): void {
        console.log(`Tablet. Model: ${this.model} - Company: ${this.company}`);
    }
}
import {Smartphone} from "./mobiles";

window.onload = () => {
    let mi: Smartphone = new Smartphone();
    mi.company = "Xiaomi";
    mi.model = "RedMi 4 Pro";
    mi.displayInfo();
};
"use strict";
var Smartphone = (function () {
    function Smartphone() {
    }
    Smartphone.prototype.displayInfo = function () {
        console.log("Smartphone. Model: " + this.model + " - Company: " + this.company);
    };
    return Smartphone;
}());
exports.Smartphone = Smartphone;
var Tablet = (function () {
    function Tablet() {
    }
    Tablet.prototype.displayInfo = function () {
        console.log("Tablet. Model: " + this.model + " - Company: " + this.company);
    };
    return Tablet;
}());
exports.Tablet = Tablet;
//# sourceMappingURL=mobiles.js.map
"use strict";
var mobiles_1 = require("./mobiles"); //Error Get here
window.onload = function () {
    var mi = new mobiles_1.Smartphone();
    mi.company = "Xiaomi";
    mi.model = "RedMi 4 Pro";
    mi.displayInfo();
};
//# sourceMappingURL=app.js.map
编译文件app.js的内容后

export interface Device {
    model: string;
    company: string;
    displayInfo(): void;
}

export class Smartphone implements Device {
    model: string;
    company: string;

    displayInfo(): void {
        console.log(`Smartphone. Model: ${this.model} - Company: ${this.company}`);
    }
}

export class Tablet implements Device {
    model: string;
    company: string;

    displayInfo(): void {
        console.log(`Tablet. Model: ${this.model} - Company: ${this.company}`);
    }
}
import {Smartphone} from "./mobiles";

window.onload = () => {
    let mi: Smartphone = new Smartphone();
    mi.company = "Xiaomi";
    mi.model = "RedMi 4 Pro";
    mi.displayInfo();
};
"use strict";
var Smartphone = (function () {
    function Smartphone() {
    }
    Smartphone.prototype.displayInfo = function () {
        console.log("Smartphone. Model: " + this.model + " - Company: " + this.company);
    };
    return Smartphone;
}());
exports.Smartphone = Smartphone;
var Tablet = (function () {
    function Tablet() {
    }
    Tablet.prototype.displayInfo = function () {
        console.log("Tablet. Model: " + this.model + " - Company: " + this.company);
    };
    return Tablet;
}());
exports.Tablet = Tablet;
//# sourceMappingURL=mobiles.js.map
"use strict";
var mobiles_1 = require("./mobiles"); //Error Get here
window.onload = function () {
    var mi = new mobiles_1.Smartphone();
    mi.company = "Xiaomi";
    mi.model = "RedMi 4 Pro";
    mi.displayInfo();
};
//# sourceMappingURL=app.js.map

我建议您使用angular2本机生命周期挂钩,而不是
app.ts
文件中的
window.onload
。在项目中不使用angular2