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

ng-click #42

Closed
wants to merge 1 commit into from
Closed

ng-click #42

wants to merge 1 commit into from

Conversation

ShaneChesnutt
Copy link
Contributor

No description provided.

@MatthewVita
Copy link
Member

MatthewVita commented Dec 12, 2016

@ShaneChesnutt actually you need to add the following to your example:

constructor(props) {
  super(props);

  // TODO: express this in terms of Redux (Shane, you can leave this todo in for now. Will get to it later)
  this.state = {
    foo: 'bar'
  };
    
  this.clickHandler = this.clickHandler.bind(this);
}

clickHandler() {
  console.log(this.state.foo); // => 'bar'
}

@MatthewVita
Copy link
Member

Can add a note saying "you'll need to bind the click handler to the class so that the this context (and, therefore, the component state) is accessible.

@MatthewVita
Copy link
Member

MatthewVita commented Dec 12, 2016

@ShaneChesnutt you're going to kill me, but I just realized one more thing we need to document with this section... how do you pass in the target data member with the click handler? For example, let's say you have the following data structure:

[{
  first: 'john',
  last: 'doe',
  email: 'john@doe.com'
}, {
  first: 'Mary',
  last: 'doe',
  email: 'mary@doe.com'
}]

and you ng-repeat it with an <button ng-click='vm.edit(row)'>edit</button> for each row, how does vm.edit function know which array item to set row.editMode = true for. We know this is rather easy in angular by looking for the index of the item in the larger array, but how would this work in React?

@ShaneChesnutt
Copy link
Contributor Author

ShaneChesnutt commented Dec 12, 2016 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants