Stimulus Discourse

Handbook External Resources example with fetch and this


I’m following the handbook example and this is undefined in the response.

My actual code is below. I don’t see how it is different from this.element.innerHTML = html in the handbook example.

connect() {

updateStatus() {
    .then(response => response.json())
    .then(status => {
      this.element.classList.add(status["duty_status"]) // `this` is undefined here


Thanks for the help/suggestions.


Hmm, your code looks fine to me. What kind of build tooling are you using to compile your JavaScript?

I made an example using and it works as expected: controllers/json_loader_controller.js :point_right: