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

Expose parent scope to event handlers #45

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

OzzieOrca
Copy link

This will be a contrived example but my use case is:

<div ng-repeat="question in $ctrl.questions">
    <div ng-sortable="$ctrl.sortableOptions">
        <div ng-repeat="answer in question.answers">
            {{answer}}
        </div>
    </div>
</div>
this.sortableOptions = {
    onEnd: ({ scope: { question } }) => {
       this.saveQuestion(question);
    },
};

This does feel hacky but without it, I'm not sure how to know which question had the sortable that just changed. I suppose making a nested component would make the scope available but I've got a giant component I wasn't intending on refactoring right now.

Other libraries (such as angular-ui-sortable) use attributes for event handlers where you can pass an expression from the template to do this.

I'm just trying to get off jQuery :)

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.

1 participant