2

How to passing value from component to js file ? Thank you very much.

app.component.html

<table>
  <tr>
    <td>Time</td>
    <td>Title</td>
  </tr>
  <tr *ngFor="let data of dataList">
    <td>
      <a href="#" onClick="openWin()">{{data.createDatetime}}</a>
    </td>
    <td>
      <a href="#" onClick="openWin(data.title)">{{data.title}}</a>
    </td>
  </tr>
</table>

script.js (in assets folder)

function openWin(title) {
    // open popup windows
    // show title
}
3
  • You can pass data in parameter like (click)="openWin(data)" Commented Jan 6, 2018 at 8:11
  • In script.js how to use data, example show data.title ? Thank you very much. Commented Jan 6, 2018 at 8:16
  • You will get whole object so function openWin(data) { console.log(data.title); } ` Commented Jan 6, 2018 at 8:18

1 Answer 1

1

You need to use (click) instead of onclick with angular

<a href="#" (click)="openWin(data)">

And inside ts,

openWin(data:any){
   console.log(data.title);
}
Sign up to request clarification or add additional context in comments.

Comments

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.