Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target doesn't work #156

Closed
ghost opened this issue May 11, 2018 · 6 comments
Closed

Target doesn't work #156

ghost opened this issue May 11, 2018 · 6 comments

Comments

@ghost
Copy link

ghost commented May 11, 2018

When i try to use target, i get this error:

TypeError: undefined is not an object (evaluating 'this.homeTarget.innerHTML'

this.homeTarget is undefined

HTML:

<div class="home" id="home" data-controller="main" data-action="click->main#start_quiz" data-target="main.home">
	<div class="home__wrapper">
		<div class="home__heading">BEM VINDO AO QUIZ</div>
		<div class="home__subheading">TOQUE NA TELA PARA INICIAR</div>
	</div>
</div>

Javascript:

import { Controller } from "stimulus"
export default class extends Controller {
	static targets = [ "home" ]
        start_quiz() {
		console.log("home:", this.homeTarget.innerHTML)
	}
}

What's wrong here?

@ngan
Copy link

ngan commented May 11, 2018

Why not just use this.element? It'll give you the element that your controller was declared on. Not sure if the controller element and the target element can be the same 🤷‍♂️

@ghost
Copy link
Author

ghost commented May 11, 2018

well, it can work, but my issue actually is: why the target is not working?

@adrienpoly
Copy link
Member

@javan
Copy link
Contributor

javan commented May 12, 2018

What version of Stimulus are you using? Are you using the "standard" webpack + babel setup or another build system?

@ghost
Copy link
Author

ghost commented May 14, 2018

im using it on rails with webpackler, stimulus 0.9.0

@javan
Copy link
Contributor

javan commented May 14, 2018

That explains it. Target properties were added in 1.0.0: https://github.com/stimulusjs/stimulus/releases/tag/v1.0.0

@javan javan closed this as completed May 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants