[英]Angular 2: exporting an export into a component file
In my Angular 2 app, I have a settings.js
file with various exports that I want to use throughout the application: 在我的Angular 2应用程序中,我有一个
settings.js
文件,其中包含我要在整个应用程序中使用的各种导出:
exports.httpPort = 9000;
exports.httpsPort = 1435;
exports.segmentID = 1;
I want to export some of these into my ts component file query.component.ts
, but I'm at a loss on what the correct syntax to do so is. 我想将其中一些导出到我的ts组件文件
query.component.ts
,但是我对正确的语法query.component.ts
。
I see that many .js files have something along the lines of 我看到许多.js文件都有类似的内容
var settings = require('../../settings');
which grabs the settings file and then 抓取设置文件,然后
settings.dbConfig
Which calls the export, but it doesn't work on my component file. 该调用导出,但不适用于我的组件文件。
This is my project file structure: 这是我的项目文件结构:
component.ts - project/web/src/app/component.ts
component.ts-
project/web/src/app/component.ts
-Place where I want to import an export from settings.js. -我要从settings.js导入导出的位置。
settings.js - project/server/settings.js
settings.js-
project/server/settings.js
-File where I want to make the export. -我要进行导出的文件。
In the component class you can do: 在组件类中,您可以执行以下操作:
...
import {httpPort} from "../../../server/settings.js"
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.