桶 - 如何导出常量

时间:2017-01-27 12:14:35

标签: typescript

我想创建一个常量并使用index.ts导出它。但是当我尝试使用索引路径而不是完整的const路径加载const时,我得到错误"找不到模块./form-validation"。

app └───... └───translation │ │ translation.service.ts │ │ │ └───form-validation │ │ pt-BR.ts │ │ index.ts

Const文件

PT-BR.ts

export const formValidationPtBr  = {
  "minlength" : "tamanho"
}

index.ts

export { formValidationPtBr } from './pt-BR';

工作结构

translation.service.ts

import { formValidationPtBr } from './form-validation/pt-BR'; // here the import os OK and I can access the const `formValidationPtBr`.

@Injectable()
export class TranslationService {

  constructor() {
    console.log(formValidationPtBr);
  }

}

通缉结构(不工作)

translation.service.ts

import { formValidationPtBr } from './form-validation'; // here the import desn't work saying "Cannot find module `./form-validation`"

@Injectable()
export class TranslationService {

  constructor() {
    console.log(formValidationPtBr);
  }

}

0 个答案:

没有答案