How to declare a constant file with Ember.js

how to create a constant class or helper in Ember?

something like creating a .js constant and add

export const testme = 3;
export const testtoo = 4;

then in the controller I would

import constants from 'constants';
+4
source share
1 answer

you are exporting correctly but importing incorrectly your import should look like this

import { testme, testtoo } from './constants';

but I would use a different approach and instead create a hash constant (in the constants.js file)

export default { TEST1: '1', TEST2: '2' };

then import e.g.

import CONSTANTS from 'constants'

CONSTANTS.TEST1 === '1'
+7
source

Source: https://habr.com/ru/post/1622267/


All Articles