0
  • I have a directive (Just a button).
  • This directive has an isolated scope.
  • I want to update the object in my parent scope by clicking on the button.
  • But the function is not being called.

This is the plunker.

I've tried defining the function in both the link function and the controller, and they didn't work

I know I am missing something very basic. Need some form of explanation on why this is happening. Have tried looking through a lot of the other questions but I still couldn't find a clear answer.

Thanks in advance!

2
  • There are already ng-click and ng-mouseover directives. Hope you have seen\considered the same. Commented Dec 19, 2013 at 10:26
  • @Chandermani yes I've seen a few of them but I still do not understand why ng-click works with a function (declared in the link function) on an inherited scope, but not an isolated scope. Commented Dec 19, 2013 at 15:04

1 Answer 1

1

You forget to scope.$apply()! See forked plunk: http://plnkr.co/edit/zo1GrfwyQ8T82TJiW16h?p=preview

You need to call $apply() every time an external source touches Angular values (in this case the "external source" is the browser event handled by on()).

Sign up to request clarification or add additional context in comments.

1 Comment

I think you've used the wrong plunker, but I got your point. Use $apply after setting the data in the click handler. I've also updated the plunker with the correct one

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.