[]
notation expects expressions
, it tries to evaluate url('kgfdgf')
, hence your error.
[style.background-color]
is a possible binding, [style.background-image]
is not ( PLUNKER
)
Update:
Which is a side-effect of sanitizing the css. See github issue and this and this.
Workaround: PLUNKER
Where QuentinFchx mentioned a workaround using pipe
import {DomSanitizationService} from '@angular/platform-browser';
@Pipe({name: 'safe'})
export class SafePipe {
constructor(sanitizer:DomSanitizationService){
this.sanitizer = sanitizer;
}
transform(style) {
return this.sanitizer.bypassSecurityTrustStyle(style);
}
}
Usage: <div [style.transform]="'rotate(7deg)' | safe"> asdf </div>
Alternative: PLUNKER
[ngStyle]="{'background-image': 'url(' + (model.cover || 'client/img/profile_user/test.png') + ')'}"