简体   繁体   English

Angular 2:将导出导出到组件文件

[英]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.

相关问题 Angular 2:从settings.js导入导出到组件文件 - Angular 2: importing an export from settings.js into a component file 错误说我忘记从它定义的文件中导出我的组件,但我没有导出任何自定义组件(React) - The error said that I forgot to export my component from the file it's defined in but I am not exporting any custom components(React) 即使在 ReactJS 中导出组件后,默认导出错误 - Default export error even after exporting the component in ReactJS 将 JavaScript React Class 组件导出到 TypeScript 文件中 - Exporting a JavaScript React Class Component into a TypeScript file Angular 8 - 如何将数据从 1 组件导出到 2 再到 3 - Angular 8 - How to export data from 1 component to 2 and then to 3 module.export不导出文件,要导入到main.js中 - module.export not exporting the file, to be imported in main.js 在React中导出组件时如何避免使用默认导出? - How can I avoid using default export when exporting a component in React? 将 React 组件转换为 HTML 字符串(导出到文件) - Convert React-component to HTML-string (exporting to file) 将自定义javascript文件导出到Vue组件 - Export custom javascript file to a Vue component 如何使用angular2-highcharts和AOT编译器导入exporting.js和export-data.js? - How to import exporting.js and export-data.js using angular2-highcharts and AOT compiler?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM