# How to create Constant.ts

**URL:** <https://discourse.aurelia.io/t/how-to-create-constant-ts/1440>\
**Category:** Help Requests\
**Created:** [July 17, 2018, 9:29am UTC](https://discourse.aurelia.io/t/how-to-create-constant-ts/1440 "2018-07-17T09:29:24Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Calabonga](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/calabonga/32/89_2.png) [@Calabonga](https://discourse.aurelia.io/u/Calabonga)\
**Post date:** [July 17, 2018, 9:29am UTC](https://discourse.aurelia.io/t/how-to-create-constant-ts/1440/1 "2018-07-17T09:29:24Z")

</div>

How to create Constant.ts for sharing it between modules (components). Should it be injected or use another way? Please help.

PS: “dotnet new Aurelia” project

---

<div class="post-metadata">

**Author:** ![dnkm](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/dnkm/32/594_2.png) [@dnkm](https://discourse.aurelia.io/u/dnkm)\
**Post date:** [July 17, 2018, 10:08am UTC](https://discourse.aurelia.io/t/how-to-create-constant-ts/1440/2 "2018-07-17T10:08:39Z")

</div>

I have applicationConstants.js in the application root that I just inject as required. Works fine for my needs.

---

<div class="post-metadata">

**Author:** ![Calabonga](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/calabonga/32/89_2.png) [@Calabonga](https://discourse.aurelia.io/u/Calabonga)\
**Post date:** [July 18, 2018, 1:32pm UTC](https://discourse.aurelia.io/t/how-to-create-constant-ts/1440/3 "2018-07-18T13:32:31Z")

</div>

Sorry, my questions is not properly sound, I want to ask how I can inject correctly this file?

---

<div class="post-metadata">

**Author:** ![dnkm](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/dnkm/32/594_2.png) [@dnkm](https://discourse.aurelia.io/u/dnkm)\
**Post date:** [July 18, 2018, 7:17pm UTC](https://discourse.aurelia.io/t/how-to-create-constant-ts/1440/4 "2018-07-18T19:17:17Z")

</div>

So I have something like this:

**applicationConstants.js**

```javascript
export const Titles = [
    { title: "Mr" },
    { title: "Mrs" },
    { title: "Ms" },
    { title: "Miss" },
    { title: "Dr" },
    { title: "Prof" },
    { title: "Master" },
    { title: "Rev" },
    { title: "Sir" },
    { title: "Lady" },
    { title: "Lord" },
    { title: "Mx" }
];

```

**addUser.js**

```javascript
import { Titles } from "applicationConstants";

@inject(Titles)
export class AddUser {
    constructor(Titles) {
        this.titles = Titles;
    }
}

```

Then I can just `repeat.for` through `this.titles` in the view to put them in a select list.

---

<div class="post-metadata">

**Author:** ![Calabonga](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/calabonga/32/89_2.png) [@Calabonga](https://discourse.aurelia.io/u/Calabonga)\
**Post date:** [July 18, 2018, 11:45pm UTC](https://discourse.aurelia.io/t/how-to-create-constant-ts/1440/5 "2018-07-18T23:45:18Z")

</div>

Thank you very match! This is what I need.

---

<div class="post-metadata">

**Author:** ![Calabonga](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/calabonga/32/89_2.png) [@Calabonga](https://discourse.aurelia.io/u/Calabonga)\
**Post date:** [July 19, 2018, 1:51am UTC](https://discourse.aurelia.io/t/how-to-create-constant-ts/1440/6 "2018-07-19T01:51:35Z")

</div>

Unfortunately this is not work for me. I’m trying to inject something like that:

```
export const AppSettings = {
    BASE_URL: "http://localhost:64481",
    GET_QUIZ_URL: "/api/data"
}

```

but the AppSetting is undefined:

![2018-07-19_0848](https://canada1.discourse-cdn.com/flex027/uploads/aurelia/original/1X/c0ffef3e323333cc9ee2a550b725d68ba27eadf5.png)

---

<div class="post-metadata">

**Author:** ![huochunpeng](https://avatars.discourse-cdn.com/v4/letter/h/49beb7/32.png) [@huochunpeng](https://discourse.aurelia.io/u/huochunpeng)\
**Post date:** [July 19, 2018, 2:53am UTC](https://discourse.aurelia.io/t/how-to-create-constant-ts/1440/7 "2018-07-19T02:53:34Z")

</div>

It is in one line, `@inject(ApplicationConstants, AppSettings)`  
The order must match the order of constructor arguments.

---

<div class="post-metadata">

**Author:** ![Calabonga](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/calabonga/32/89_2.png) [@Calabonga](https://discourse.aurelia.io/u/Calabonga)\
**Post date:** [July 19, 2018, 4:24am UTC](https://discourse.aurelia.io/t/how-to-create-constant-ts/1440/8 "2018-07-19T04:24:53Z")

</div>

This is work great! Thanks!

![image](https://canada1.discourse-cdn.com/flex027/uploads/aurelia/original/1X/d068902ff4bae5e7ec082803cfd5570272bc2130.png)

But what about @autoinject()

The “emitDecoratorMetadata”: already true

```
import { autoinject, inject } from 'aurelia-dependency-injection';
import { AppSettings } from "common/app-settings";
import { HttpClient } from 'aurelia-fetch-client';

@autoinject()
export class QuizService {

    settings : any;

    constructor(private httpClient: HttpClient, AppSettings) {
        this.httpClient = httpClient;
        this.settings = AppSettings;
    }
}

```

Can I use @autoinect?

---

<div class="post-metadata">

**Author:** ![Calabonga](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/calabonga/32/89_2.png) [@Calabonga](https://discourse.aurelia.io/u/Calabonga)\
**Post date:** [July 19, 2018, 4:46am UTC](https://discourse.aurelia.io/t/how-to-create-constant-ts/1440/9 "2018-07-19T04:46:23Z")

</div>

@inject **vs** static @inject {…}

What is the best (preferred) way to do injection?

---

<div class="post-metadata">

**Author:** ![dnkm](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/dnkm/32/594_2.png) [@dnkm](https://discourse.aurelia.io/u/dnkm)\
**Post date:** [July 19, 2018, 9:48am UTC](https://discourse.aurelia.io/t/how-to-create-constant-ts/1440/10 "2018-07-19T09:48:35Z")

</div>

`@autoinject` is typescript only I believe - I’m not using typescript, but I’d probably use it if I was. Seems like an excellent idea to me. As for `@inject` and `static inject`, I don’t think there’s any difference really - just a matter of preference. I assume it’s handled exactly the same behind the scenes.

---

<div class="post-metadata">

**Author:** ![Calabonga](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/calabonga/32/89_2.png) [@Calabonga](https://discourse.aurelia.io/u/Calabonga)\
**Post date:** [July 19, 2018, 3:10pm UTC](https://discourse.aurelia.io/t/how-to-create-constant-ts/1440/11 "2018-07-19T15:10:28Z")

</div>

Thank you very match! You save my day!
