I have this pipe:
@Pipe({
name: 'transformNull'
})
export class TransformNull implements PipeTransform {
transform(value: any) {
switch(value){
case null:
case undefined:
case "null":
case "undefined":
value = null;
break;
default:
if(typeof(value) == "string"){
value = value.trim();
}
break;
}
return value.toString();
}
}
and this is the html code:
<input type="text" formControlName="chipNumber" autocorrect="off" autocapitalize="off" spellcheck="off" name="chipNumber" class="form-control" id="chipNumber" placeholder="Αριθμός Microchip" [ngModel]="pet.chipNumber | transformNull" (ngModelChange)="pet.chipNumber.value = $event">
When i run on JIT (ng build --prod
), the pipe works as it should, when a field has "null" then ngModel returns an empty field from mongo.
When i run ng build --prod --aot
then i receive the following error:
TypeError: Cannot create property 'value' on string ''
and here is the aot code:
t.prototype.handleEvent_267 = function(e, t) {
this.markPathToRootAsCheckOnce();
var n = !0;
if (n = this._DefaultValueAccessor_267_3.handleEvent(e, t) && n,
"ngModelChange" == e) {
var i = (this.context.pet.chipNumber.value = t) !== !1;
n = i && n
}
return n
}
funny thing is, in every other page that the pipe exists, it works as it should in aot. Just in this page i get this error. I resolve all routes with a resolver so data is ok, it comes in as it should.