Im currently trying to get a direction indicator realised in an ionic 2 App. I tried it with several possible solutions (Pipe/Function) and none works for me. on the console i get a message
WARNING: sanitizing unsafe style value SafeValue must use [property]=binding: transform:rotate(48deg);[...]
even if the variable is marked as being type SafeStyleImpl suggesting me that the whole procedure worked. After switching to use property binding i get the same message but now as ng-reflect-ng-style within the html tag
My guess it’s some tiny thing I’m missing.
I could reproduce the problem in a ionic sample app (Template: blank)
home.ts
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import {DomSanitizer}from '@angular/platform-browser';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
public angle:number=42;
public angleStyle:any;
constructor(public navCtrl: NavController,protected Sanitizer: DomSanitizer) {
this.turnAngle(0);
}
turnAngle =function (angle){
this.angle=this.angle+angle;
let style="transform:rotate("+this.angle+"deg);";
this.angleStyle=this.Sanitizer.bypassSecurityTrustStyle(style);
console.log(this.angleStyle);
}
}
Warning: It turned out this works only on Android and ionic serve! When running on ios it breaks the complete app. Most parts turn white. Some texts disappear and lots of layout gets completely lost.
According to this post:
the correct way to do it would be to use [style.transform] instead of [style]. But using this the style is completely removed from the template.
Can you show the new code in your template? Also, when simply running ng serve and checking in e.g. Chrome, do you see any warnings/errors or anything out of the ordinary in the console?
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
public angle:number=42;
constructor(public navCtrl: NavController) {
}
}
For now I’m quiet happy with that. My remaining Question would be: Why is this working without bypassSecurityTrustStyle? Is this a bug or can i rely on this?