skip to Main Content

Below is simple html code, am trying to call function , bt its not getting fire ,,, is anyone know..

 <div (click)="openPreview(modelvalue)">
     <i class="icon-image-fui"></i>
     {{modelvalue}}
  </div>
  <label (click)="donwload(modelvalue)">Download</label>

didnt apply any css class,,, usually should not happen

2

Answers


  1. // You will need to define modelValue somewhere in your script.
    var modelValue = 'Your Model Value Here';
    
    function openPreview(value) {
      alert("Preview: " + value);
    }
    
    function download(value) {
      alert("Download: " + value);
    }
    
    // Set the display value
    document.getElementById('modelValueDisplay').textContent = modelValue;
    <div id="preview" onclick="openPreview(modelValue)">
      <i class="icon-image-fui"></i>
      <span id="modelValueDisplay"></span>
    </div>
    <label id="download" onclick="download(modelValue)">Download</label>

    you’re trying to use Angular syntax in plain HTML Angular uses (click) to bind click events in its templates which will not work if you are not actually using Angular or if Angular is not properly set up in your project.

    Login or Signup to reply.
  2. var modelValue = 'Example Model Value';
    
    document.getElementById('preview').addEventListener('click', function() {
      openPreview(modelValue);
    });
    
    document.getElementById('download').addEventListener('click', function() {
      download(modelValue);
    });
    
    function openPreview(value) {
      console.log("Preview clicked with value:", value);
    }
    
    function download(value) {
      console.log("Download clicked with value:", value);
    }
    <div id="preview">
      <i class="icon-image-fui"></i>
      <span id="modelValueDisplay">Model Value</span>
    </div>
    <label id="download">Download</label>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search