I am currently working on creating a cell renderer in Angular that converts IP addresses into clickable SSH links. Below is the code for the renderer component:
import { Component, OnInit, OnDestroy } from "@angular/core";
import { DomSanitizer, SafeUrl } from "@angular/platform-browser";
import { ICellRendererAngularComp } from "ag-grid-angular";
import { ICellRendererParams } from "ag-grid-community";
const username = "me";
/**
* SSHCellRendererComponent is an AG-Grid cell renderer that provides ssh:// links as content.
*/
@Component({
selector: "ssh-cell-renderer",
styleUrls: ["./ssh-cell-renderer.component.scss"],
templateUrl: "./ssh-cell-renderer.component.html"
})
export class SSHCellRendererComponent implements ICellRendererAngularComp {
/** The IP address or hostname to which the SSH link will point. */
public get value(): string {
return this.val;
}
private val = "";
/** The SSH URL to use. */
public get href(): SafeUrl {
const url = `ssh://${username}@${this.value}`;
return this.sanitizer.bypassSecurityTrustUrl(url);
}
constructor(private readonly sanitizer: DomSanitizer) {}
/** Called by the AG-Grid API at initialization */
public refresh(params: ICellRendererParams): boolean {
this.val = params.value;
return true;
}
/** called after ag-grid is initialized */
public agInit(params: ICellRendererParams): void {
console.log("has value?:", Object.prototype.hasOwnProperty.call(params, "value"));
console.log("getval:", params.getValue());
this.val = params.value;
}
}
The template for this renderer looks like:
<a [href]="href" target="_blank">{{value}}</a>
Despite being similar to what I have done in AngularJS, this implementation does not work as expected. The rendered cells display content as follows:
<a href="ssh://me@" target="_blank"></a>
Upon logging information using the console in agInit
:
16:34:38.554 has value?: false ssh-cell-renderer.component.ts:62:10
16:34:38.555 getval: undefined ssh-cell-renderer.component.ts:63:10
It becomes apparent that the object passed to agInit
(and potentially refresh
) is not of type ICellRendererParams
. Additionally, the getValue
function returns
undefined</code consistently. While I can access the <code>data
property and confirm that the rendered value is not undefined
, using this approach would require creating separate components for IPv4 and IPv6 addresses, leading to redundant code.
What could be causing this issue?