Reputation: 15501
This is a followup to this question.
I am using setTimeout()
to increment the stopwatch milliseconds and have following code to display it.
domAttr.set("milliseconds", "innerHTML", milliseconds);
However, I am getting an error:
Uncaught TypeError: Object #<HTMLDocument> has no method 'set'
even though I have included the required module dojo/dom-attr
.
Here is my fiddle so far. What am I doing wrong?
Upvotes: 1
Views: 94
Reputation: 44685
It's because your modules and your callbacks are not matching. You have the following modules + callback:
require(["dijit/form/Button", "dojo/dom", "dojo/domReady!", "dojo/dom-attr"], function(Button, dom, domAttr) {
// code
});
Your function parameters will in fact contain the result of the module corresponding to it (in the same order), so that means:
dijit/form/Button
= Button
(ok)dojo/dom
= dom
(ok)dojo/domReady!
= domAttr
(not ok)Every module has a result, even the ones that might not seem to have a useful result (like dojo/domReady!
). So because you're calling the set()
function on dojo/domReady!
(which has no such function) your code fails.
The solution is to move the dojo/domReady!
module to the end of the list, for example:
require(["dijit/form/Button", "dojo/dom", "dojo/dom-attr", "dojo/domReady!"], function(Button, dom, domAttr) {
// code
});
I recently wrote a complete guide/answer about how the require()
stuff works which might be interesting to read if you don't understand it. I also updated your JSFiddle.
Upvotes: 2