Hi
The change to the model is made outside the 'scope' of angular (in the
click handler).
Here's the corrected code, with the model update wrapped in an apply, i.e
scope.$apply(function () {
scope.showDialog = true;
});
http://jsbin.com/guziwamu/14/edit
On Sunday, February 16, 2014 2:04:38 PM UTC+2, Misha Moroshko wrote:
>
> *LIVE DEMO <http://jsbin.com/guziwamu/1/edit>*
>
> Given the following two directives:
>
> JS:
>
> angular.module("Directives", []).directive("action",
> function($compile) {
> return {
> restrict: 'A',
> scope: {
> action: '='
> },
> link: function(scope, element) {
> scope.showDialog = false;
>
> var template = "<span dialog='showDialog'>Dialog</span>";
>
> element.append($compile(template)(scope)).on('click', function()
> {
> console.log("Setting showDialog to true");
> scope.showDialog = true;
> });
> }
> };
> }).directive("dialog", function() {
> return {
> restrict: 'A',
> scope: {
> dialog: '='
> },
> link: function(scope, element) {
> element.hide();
>
> scope.$watch('dialog', function(newValue) {
> console.log("dialog changed to " + newValue); // Not called on
> button click
> });
> }
> };
> });
>
> HTML:
>
> <button action>Click Here</button>
>
> Could you explain why setting action's showDialog doesn't trigger dialog's
> watcher?
>
> http://stackoverflow.com/q/21810486/247243
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.