2

According to the answer in Is it Possible to Update Parent Scope from Angular Directive with scope: true? it won't work to overwrite a primitive value in the parent scope from a directive since the reference is lost.

However, in this example that's exactly what's happening and the reference is kept:

http://adamalbrecht.com/2013/12/12/creating-a-simple-modal-dialog-directive-in-angular-js/

http://output.jsbin.com/neluxejuwi

Directive JS:

scope: {
      show: '='
    },
[...]
link: function(scope, element, attrs) {
      [...]
      scope.hideModal = function() {
        scope.show = false;
      };
    },

HTML:

<modal-dialog show='modalShown' width='750px' height='90%'>
  <p>Modal Content Goes here<p>
</modal-dialog>

How is this possible?

Community
  • 1
  • 1
user2906759
  • 821
  • 1
  • 9
  • 15
  • *"it won't work to overwrite a primitive value in the parent scope"* you misunderstood the answer, it's correct and nothing mystical in observed behaviour. I recommend you to invest some time into good understanding of prototypical inheritance and how it works. – dfsq Oct 22 '15 at 08:58

0 Answers0