I am not getting the right result when trying to follow the Ember interactivity: Events, classes and state module. The module asks you to tell ember to create a header.js class file and put the following in it:
import Component from ‘glimmer/component’;
import { action } from ‘ember/object’;
export default class HeaderComponent extends Component {
action
onKeyDown({ target, key }) {
let text = target.value.trim();
let hasValue = Boolean(text);
When you go to the webpage that your are serving locally, you should be able to type text and hit enter. Then an alert should show the text you typed. No alert is happening for me. I am working in visual studio code and it gives me the following error
Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning.
I'm not sure if that is related. Here is the link to my code so far on GitHub. The only thing I've tried is going back through the tutorial to see if I skipped anything. Could you tell my if skipped a step or incorrectly implemented what the module tells you to do? I have removed the 'at' symbols from the example code on here because I think they were being treated like mentions.
In Discourse, you can use three single quotes (```) at the start and end of a block of code (same as Markdown). This is easier than using four spaces to indent the code:
import Component from '@glimmer/component';
import { action } from '@ember/object';
export default class HeaderComponent extends Component {
@action
onKeyDown({ target, key }) {
let text = target.value.trim();
let hasValue = Boolean(text);
if (key === 'Enter' && hasValue) {
alert(text);
target.value = ''
}
}
}
The tutorial has you use Ember to generate files. Those commands may generate more than just the files mentioned to edit, so try to use ember when the tutorial asks you to do that.
For the error, the most effective thing is to copy and paste that error into a search engine and find a webpage that relates to your issue. I found these:
Working through errors in a tutorial is more than half of learning, unfortunately. If the MDN tutorial has too many sharp edges, you may want to start over with the official EmberJS tutorial: