简体   繁体   English

Angular UI Bootstrap进度栏-如何使用表达式计算“值”属性?

[英]Angular UI Bootstrap progress bar - how to calculate “value” attribute with expression?

I want to use UI bootstrap progressbar inside a table to give a visual representation of some statistics. 我想在表中使用UI引导进度条来提供一些统计信息的可视化表示。 The stats are percentages so it should work quite nicely, ie the higher the percentage the longer the bar. 统计数据是百分比,因此它应该可以很好地工作,即百分比越高,指示条越长。

I need to calculate the value with an expression, so I'm creating the progressbar element like so inside the table column: 我需要使用表达式来计算值,所以我要在表列内创建progressbar元素:

<uib-progressbar type="info" value="{{ ((statValue / total) * 100) }}"></uib-progressbar>

Just to clarify, that's a simplified example, but the point is I cannot get any kind of expression to work when trying to calculate the value attribute. 只是为了澄清,这是一个简化的示例,但要点是,在尝试计算value属性时,我无法获得任何形式的表达式。

It works if I give the attribute a different name and it works if I create a "value" attribute on any other type of element (eg a div). 如果我给该属性一个不同的名称,它会起作用;如果我在任何其他类型的元素(例如div)上创建一个“值”属性,它将起作用。 It just does not seem to work for the value attribute on the uib-progressbar element, which is exactly where I need it! uib-progressbar元素上的value属性似乎不起作用,这正是我需要的地方!

The error I get in the browser console is: 我在浏览器控制台中遇到的错误是:

"Error: [$parse:syntax] Syntax Error: Token '{' invalid key at column 2 of the expression [{{ ((statValue / total) * 100) }}] starting at [{ ((statValue / total) * 100) }}]." “错误:[$ parse:syntax]语法错误:表达式[{{((statValue / total)* 100)}}]]第2列的令牌'{'无效键,从[{((statValue / total)* 100)}}]。”

I'm using angularjs 1.4.9 and angular-ui-bootstrap 1.1.2. 我正在使用angularjs 1.4.9和angular-ui-bootstrap 1.1.2。

How do I get this to work? 我该如何工作?

value attribute should not be using interpolation {{}} inside value attribute, you could directly get scope variable values in it, like other directive of angular does ng-click , ng-if , etc. value属性不应在value属性内部使用插值{{}} ,您可以直接在其中获取范围变量值,就像angular的其他指令ng-clickng-if等一样。

<uib-progressbar type="info" value="((statValue / total) * 100)"></uib-progressbar>

Sample Here 在这里取样

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM