我的目标是使用“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
内部的某些内容? - Günter Zöchbauer