У меня возникла проблема, я хочу преобразовать сгенерированный HTML-код в таблицу материалов с помощью Pipe, но она не работает.
код выглядит так:
pipe.ts
import { Pipe, PipeTransform } from "@angular/core";
import * as _ from "underscore";
@Pipe({ name: "customPipeChecks" })
export class CustomPipeChecks implements PipeTransform {
transform(
elementValue: {},
elementProperty: string,
object: {},
customPipeFunction: any,
defaultValue: string
) {
if (customPipeFunction != null && _.isFunction(customPipeFunction)) {
console.log(customPipeFunction(elementValue, elementProperty, object));
return customPipeFunction(elementValue, elementProperty, object);
} else {
if (defaultValue) {
return defaultValue;
}
return elementValue;
}
}
}
сгенерированная функция
private setCustomValueFunction() {
this.customValueFunction = (
elemValue: string,
elemKey: string,
elem: {}
) => {
if (elemKey === "vin") {
elemValue = "<button>zrdzdrz</button>";
}
return elemValue;
};
}
эта функция генерирует строку HTML.
HTML-код выглядит так:
<td
mat-cell
*matCellDef="let cellData"
class="{{
cellData[colName]
| customPipeChecks: colName:cellData:customCssFunction:' '
}}"
innerHtml="{{
cellData[colName]
| customPipeChecks: colName:cellData:customValueFunction
}}">
</td>
Когда приложение загружено, оно будет отображать только 'zrdzdrz' только текст (внутренний HTML-код нужной кнопки), без кнопки (которая предназначена для переноса текста).
Есть предложения?
С наилучшими пожеланиями,
Leo