1

I've added this code to web/static/js/app.js,

export var App = {
  run: function(){
    console.log("Hello!")
  }
}

Then add this in web/templates/layout/app.html.eex

<script>require("web/static/js/app").App.run()</script>

Then refresh the browse its showing this in console:

TypeError: require(...).App is undefined
<script>require("web/static/js/app").App.run()</script>

Some one please tell me how to finish it.

TheAnh
  • 2,813
  • 2
  • 15
  • 20
Carey
  • 307
  • 2
  • 5
  • 13
  • Did you put it below this line `` – TheAnh Sep 28 '16 at 06:35
  • yes, thats my code – Carey Sep 28 '16 at 06:40
  • @Carey do you see a line containing `require.register("web/static/js/app.js"` in http://localhost:4000/js/app.js (or wherever you're running it)? – Dogbert Sep 28 '16 at 07:59
  • @Dogbert Yes Its contains – Carey Sep 28 '16 at 08:09
  • @Carey and does it contain `var App = { ... run: function() { console.log ... } ... }`? What's the value of `require("web/static/js/app")` in the browser console? (The code in the question works fine for me.) – Dogbert Sep 28 '16 at 10:46
  • Can confirm this should work, double check if everything is in order and make sure brunch compiled `app.js` correctly – Jonas Dellinger Sep 28 '16 at 12:37
  • @Dogbert Did you mean this `require.register("web/static/js/app.js", function(exports, require, module) { ` contain `var App ... ` ? , its not contain , i've brunch compiled it , but still so. – Carey Sep 29 '16 at 03:01

0 Answers0