I am new to Angular and do not understand why the ng-if and (click) events are not working from kendo grid column template.
I want a button which needs to be conditionally visible and on click I need to navigate to other page in spa. With command I couldn't dynamically handle the visibility based on cell value. So, chose template, but with template click event is not working.
Here is my component:
import { Component, Output, Input } from '@angular/core';
import { ReplaySubject } from 'rxjs/Rx';
import { ROUTER_DIRECTIVES, Router } from '@angular/router-deprecated';
import { TWCGridComponent, PanelComponent } from 'infrastructure.export';
import { IssueDTO } from 'issue.webmodel.export';
import { IssueBusinessService } from '../../webBL/issue.business.service';
declare var $: any, moment: any;
@Component({
selector: 'twc-issue-list',
templateUrl: 'webApp/issueDetail/Shared/sections/issueList/issue.list.template.html',
directives: [ROUTER_DIRECTIVES, TWCGridComponent, PanelComponent],
viewProviders: [],
styles: [`
:host { display: block; }
`]
})
export class IssueListComponent {
dataSource: Array<IssueDTO> = [];
gridOptions: kendo.ui.GridOptions;
child: JQuery;
// private $el: JQuery;
@Output() knownIssuesCount: ReplaySubject<{}> = new ReplaySubject(1);
@Input() set searchParams(params: any) {
if (params) {
this.initSearch(params);
}
}
constructor(private issueBusinessService: IssueBusinessService,
private router: Router
) {
this.gridOptions = {
sortable: false,
scrollable: false,
columns: [
{
field: "id", title: "Issue ID / Status / Summary", width: "40%",
template: `
<div class="cellLine">#:id# \/ <span class='status #:statusName.toLowerCase().replace(/ /g, '')#'>#:statusName.toUpperCase()#</span></div>
<div class="cellLine">#:title#</div>`
},
{
field: "category", title: "Category / Type", width: "30%",
template: `
<div class="cellLine">#:primaryIssueCategoryName#</div>
<div class="cellLine">#:primaryIssueCategoryTypeName#</div>
`
},
{
field: "updateTime", title: "Created / Updated", width: "20%",
template: this.gridFormatters.lastUpdate
},
{
field: "command", hidden: false,
template: `<div><button type="button" onclick="toggleOrder()" class='btn btn-rounded #:readAllowed# icon-twc-08'</button></div>`
};
/* tslint:disable */
function toggleOrder() {
alert("hey");
}
/* tslint:enable */
}
toggleOrder() {
alert("hey");
}
}
You need to use (click)="onClick()" and I don't see a *ngIf in your code. The "()" around the event name tells angular2 its an event.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.