Angular модальное отображение при перезагрузке? - PullRequest
1 голос
/ 27 января 2020

У меня есть этот модал, я работаю в Node Red. При входящей полезной нагрузке должно отображаться

Работает, но при загрузке или перезагрузке страницы появляется модальный режим, когда его не должно быть?

Я думаю, что это как-то связано с областью действия. .watch функция, но не могу понять это.

Любая помощь? спасибо: -)

<!-- The Modal -->
<div id="myModal" class="modal">



  <!-- Modal content -->
  <div class="modal-content">
    <div class="modal-header">
      <span class="close">&times;</span>
      <h2>{{msg.payload.navn}}</h2>
    </div>
    <div class=imgbox style="height: 200px; width: 300px" >

     <img src="{{msg.payload.icon}}" style="width: 100%;max-height: 100%" >
</div>
    <div class="modal-body">
    <p>Glasstørrelse: {{msg.payload.glas}}ml </p> 
    <p>{{msg.payload.description}} </p>  
      <p>Instruktioner: {{msg.payload.description2}}</p>
      <div>

  <input type="number" ng-model="msg.payload.nummer" name="quantity" min="0" max="1000" style= "display: none;">
  <md-button class="bt1" ng-click="send(msg)">Bestil</md-button>
</div>
    </div>

  </div>

</div>
// Get the modal
var modal = document.getElementById('myModal');

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

//show modal on msg.payload
(function(scope) {
  scope.$watch('msg', function(msg) {
    if (msg.payload) {
     modal.style.display = "block"}
  });
})(scope);

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
    modal.style.display = "none";
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
    if (event.target == modal) {
        modal.style.display = "none";
    }
}
...