【发布时间】:2016-11-02 23:56:43
【问题描述】:
我的目标是使用“styles”属性从组件变量中设置样式(在本例中为高度和宽度)。我认为有一个简单的数据绑定方法,但这可能是一厢情愿...
例如,如果我使用 html mustache 绑定,它可能如下所示:
@Component({
selector: '[sidebar]',
templateUrl: 'app/Nav/sidebar.comp.html',
styles: [`
.sidebar-nav {
overflow: scroll;
height: {{ height }};
}
.sidebar {
height: {{ 0.9 * height }};
width: {{ 0.21 * width }};
}
`]
})
export class SidebarComp {
width: number;
height: number;
constructor() {
this.height = window.innerHeight;
this.width = window.innerWidth;
}
}
显然这全错了,但我尝试了一些更可能的排列,但在 Angular 网站、Stack Overflow 或 Google 上找不到解决方案。我可能会减少使用 ngStyle 内联,但在这种情况下这并不理想。
【问题讨论】:
-
你没有展示你想要的风格。
.sidebar是SidebarComp本身还是sidebar.comp.html内部的东西?