我想在我的Angular 2應用程序中使用DataTable。但是這不起作用。 Angular 2沒有可能在模板中添加腳本標籤。你知道我該怎麼做?我想我必須在systemJs上做一些改變。如何在Angular 2中使用DataTable
list.html:
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</tfoot>
<tbody>
<tr>
<td>Gavin Cortez</td>
<td>Team Leader</td>
<td>San Francisco</td>
<td>22</td>
<td>2008/10/26</td>
<td>$235,500</td>
</tr>
<tr>
<td>Martena Mccray</td>
<td>Post-Sales support</td>
<td>Edinburgh</td>
<td>46</td>
<td>2011/03/09</td>
<td>$324,050</td>
</tr>
</tbody>
</table>
我的組件:
...
declare var jQuery:any;
..
ngOnInit():any{
console.log("Augerufen");
jQuery('#example').DataTable();
}
...
在我的index.html我已經添加了必需的libaries:提前
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/jquery.dataTables.min.css" rel="stylesheet">
<!-- jQuery -->
<script src="js/jquery.js"></script>
<script src="js/jquery.dataTables.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
謝謝!
什麼不起作用?目前尚不清楚你想要做什麼,你提供的代碼是演示代碼,並且工作正常。另外爲什麼你使用jQuery來處理角度變化事件? – Pogrindis
我想過濾表和dataTables,你可以很容易地做到這一點。我將代碼放在index.html中。但如果我使用emedded test.html,它不會執行jQuery代碼。我也用window.alert(「test」)試了一下。事件不起作用 – hamras
好吧無法在模板中添加腳本標記。 Angular 2刪除它 – hamras