Giả sử tôi có một Thành phần Angular2
//home.component.ts
import { Component } from 'angular2/core';
@Component({
selector: "home",
templateUrl: "app/components/templates/home.component.html",
styleUrls: ["app/components/styles/home.component.css"]
})
export class HomeComponent {
public width: Number;
public height: Number;
}
Tệp html mẫu cho thành phần này
//home.component.html
<div class="home-component">Some stuff in this div</div>
Và cuối cùng là tệp css cho thành phần này
//home.component.css
.home-component{
background-color: red;
width: 50px;
height: 50px;
}
Như bạn có thể thấy, có 2 thuộc tính trong lớp, width
và height
. Tôi muốn các kiểu css cho chiều rộng và chiều cao khớp với các giá trị của thuộc tính chiều rộng và chiều cao và khi thuộc tính cập nhật, chiều rộng và chiều cao của bản cập nhật div. Cách thích hợp để thực hiện điều này là gì?