我从Angular2开始,我陷入了以下简单的风格设置,我不知道为什么不起作用(https://angular.io/docs/ts/latest/guide/template-syntax.html#!#other-bindings之后)
有什么问题?
(我也试过[style.background-image]和[style.background.image]并使用组件方法来构造" url(...)"字符串)
代码:
import { Component } from '@angular/core';
@Component({
selector: 'front-page',
template: `<div [style.backgroundImage]="'url(' + headerImage + ')'" [title]="title"> </div>`
})
export class FrontPageComponent {
headerImage = "http://example.com/image.jpg"
title = "test"
}
结果:
<html>
<head>...</head>
<body>
<app-component>
<front-page>
<div title="test">
</div>
</front-page>
</app-component>
</body>
</html>