如何在行表angular2中设置事件单击链接a

时间:2017-07-10 09:21:03

标签: angular

目前,我使用Loaddata函数将数据绑定到表。但是事件点击链接标记<a>未激活。请帮我。 在Brand.component.ts中:

loadData(data?: { page: number, page_size: number, category_id: number }) {
        this.brandService.all().subscribe(res => {
            this.brands = res;
            let source = [];
            this.brands.forEach((brand: any) => {
                let item = [];
                item.push(brand.name);
                item.push('<img src="' + brand.image + '" width="100" height="100" />');
                item.push("<a href=\"javascript:void(0);\""+ this.elRef.nativeElement.que  + " title=\"Sửa thông tin\" class=\"formatLink\"><i class=\"icon wb-edit blue-grey-400 mr-10\" aria-hidden=\"true\" title=\"Sửa thông tin\"></i></a>"
                    + "<a href=\"javascript:void(0);\" (click)=\"deletebrand(" + brand.id +")\"data-toggle=\"tooltip\" title=\"Xóa thông tin\" data-original-title=\"Delete\"><i aria-hidden=\"true\" class=\"icon wb-close blue-grey-400 mr-10\"></i></a>");
                source.push(item);
            });

            var table = $('#tableBrand').DataTable(
                {
                    dom: 'Bfrtip',
                    buttons: [
                        {
                            extend: 'colvis',
                            "text": "Hiển thị",
                            "className": "colvis"
                        }
                    ],
                    "bInfo": false,
                    "data": source,
                    "language": {
                        "paginate": {
                            "previous": "Trước",
                            "next": "Tiếp"
                        },
                        search: "_INPUT_",
                        searchPlaceholder: "Tìm kiếm..."
                    }

                }
            );

            $('#tableBrand tbody tr td').css("text-align","center")
        });
    }

在Brand.component.html中:

<table class="table table-hover dataTable table-striped w-full" id="tableBrand">
                <thead>
                    <tr>
                        <th>Tên thương hiệu</th>
                        <th>Hình ảnh</th>
                        <th>Hành động</th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>

0 个答案:

没有答案