Angular2 - 如何在html中将输入绑定到容器中的函数

时间:2016-07-14 00:45:44

标签: angular

这是一个示例代码:

component.ts文件

getThirty() {
 return 'width:30%'
}

html文件

<div class="progress-bar" style = "getThirty()">

这不起作用...如何将函数绑定到输入?

我也试过[style]="getThirty()",但这仍然不起作用..

请帮忙!谢谢!

2 个答案:

答案 0 :(得分:0)

我尝试使用以下方法,它适用于我。

<div class="col-md-2" style="{{getThirty()}}">
 fhyjhrtjrjrj
</div>

希望这有助于。

答案 1 :(得分:0)

您可以按照以下方式执行此操作

    模板中的
  1. <div [style.width]="getThirty">
  2. 2.在您的组件中:public getThirty = 30 +&#39;%&#39;;

    它是:)