javascript - Setting HTML element width using ng-style and percentage value in AngularJS -
I have a JSON response object that has a percentage value. For example:
{completionPercent: 42} UI results for which I'm targeting:
Line One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? one A???? | One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ??? ? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ??? ?a???? | One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? The JSON object is used as an ng-model of an element in AngularJS. Now I want to pair the completionPercent as the width of an element in AngularJS but expecting '42%' as the string like CSS width Is not the number, therefore, the following does not work : & lt; Div id = "progressBackground" ... & gt; & Lt; Div id = "progressbar" ng-model = "..." ng-style = "{'width': fill completion}" ... ... gt; & Lt; / Div & gt; & Lt; / Div & gt; Currently, I'm working on generating the whole style in this controller:
ng-style = "getStyleFromCompletionPercent ()" But this is not a good idea, because it becomes very difficult to expand the ng-style . Is there another way that clearly specifies that the width is in percent? Something like this would be ideal: ng-style = "{'width-percent': completion filling}"
The code inside your nG-style attribute is a javascript object, so you can add a percent symbol at the end of the fourth value. As you add a string to a number, it will convert the value of the width to a string.
& lt; Div id = "progressBackground" ... & gt; & Lt; Div id = "progressbar" ng-model = "..." ng-style = "{'width': converting + '%'}" ... ... gt; & Lt; / Div & gt; & Lt; / Div & gt;
Comments
Post a Comment