How to call a public JS function from component JS file

public/myjs.js

export function show() {
    console.log("Hello");
}

app/components/main-page.js

import Component from '@glimmer/component';
import { action } from '@ember/object';
import { show } from "../../public/myjs";

export default class MainPageComponent extends Component {
    @action
    helper() {
        show();
    }
  }

app/components/main-page.hbs

<button type="button" {{on "click" this.helper}}>say hello</button>

My question is how to call the function show from main-page.js? It is showing the error like no module found in the name of myjs.js

Answered on stack-overflow here: javascript - Calling a JS functions from another JS file in EmberJS - Stack Overflow

Thanks for asking!! <3

1 Like