aurelia / aurelia/framework

Injected variables in app.js don't load on initial screen

Open
#924 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11.7k
Forks
608
PR merge metrics
No merged PRs in 30d

Description

**I'm submitting a bug report**

* **Library Version:**
```
"aurelia-bootstrapper": "2.3.1",
"aurelia-fetch-client": "1.7.0",
"aurelia-framework": "1.3.0",
"aurelia-history-browser": "1.2.0",
"aurelia-loader-webpack": "2.2.1",
"aurelia-logging-console": "1.0.0",
"aurelia-pal-browser": "1.8.0",
"aurelia-polyfills": "1.3.0",
"aurelia-router": "1.6.3",
"aurelia-templating": "1.10.1",
"aurelia-templating-binding": "1.5.2",
"aurelia-templating-resources": "1.7.1",
"aurelia-templating-router": "1.3.3",
```
and

```
"aurelia-loader-nodejs": "1.0.1",
"aurelia-pal-nodejs": "1.2.0",
"aurelia-protractor-plugin": "1.0.6",
"aurelia-testing": "1.0.0",
"aurelia-tools": "1.0.0",
"aurelia-webpack-plugin": "2.0.0-rc.5",
```
**Please tell us about your environment:**
* **Operating System:**
Windows 10

* **Node Version:**
v8.9.0

* **NPM Version:**
6.7.0

* **Aurelia CLI OR JSPM OR Webpack AND Version**
webpack 3.12.0

* **Browser:**
All

* **Language:**
ESNext

**Current behavior:**
When injecting a variable into the constructor of app.js, it is not initialized on the first screen loaded in the application. When navigating to a subsequent screen, it becomes available for use in the tags of all viewModels.

**Expected/desired behavior:**
A variable initialized in the constructor of app.js should be available to all viewModels within tags without needing to inject them into each individual viewModel

* **What is the motivation / use case for changing the behavior?**
This previously worked with aurelia-framework 1.1.5

***Example Code based on skeleton-esnext-webpack, after updating dependencies in package.json***

**constants.js :**
`export const TEST_CONST = "Constant!";`

**app.js:**
```
import {PLATFORM} from 'aurelia-pal';
import * as Constants from './constants';
import {inject} from 'aurelia-framework';

@inject(Constants)
export class App {
constructor(constants) {
this.constants = constants;
}

configureRouter(config, router) {
config.title = 'Aurelia';
config.map([
{ route: ['', 'welcome'], name: 'welcome', moduleId: PLATFORM.moduleName('./welcome'), nav: true, title: 'Welcome' },
{ route: 'users', name: 'users', moduleId: PLATFORM.moduleName('./users'), nav: true, title: 'Github Users' },
{ route: 'child-router', name: 'child-router', moduleId: PLATFORM.moduleName('./child-router'), nav: true, title: 'Child Router' }
]);

this.router = router;
}
}
```
**welcome.html:**
```


${heading}


CONSTANT: ${constants.TEST_CONST}

```
The above constant does not print in welcome.html. However, if I put it inside users.html, it does print on that screen.

Contributor guide

Open the contributing guide

Research direction

Reproduce the initial-screen behavior from app.js, constants.js, welcome.html, and users.html using the listed Aurelia and webpack versions. Compare the first routed view with the later users view and inspect the app startup and routing entry points. Done means the injected constants value renders in welcome.html on the initial screen as well as after navigation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, webpack
Domain
frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.