AngularJS / CSS - 如何选择框的宽度设置为从$作用域的价值? [英] AngularJS / CSS - How to set the width of a select box to a value from $scope?

查看:559
本文介绍了AngularJS / CSS - 如何选择框的宽度设置为从$作用域的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个选择框。第一个是变化的第二个的entires。第二个总调整它的长度最长的实际条目。但它看起来丑陋wuite如果当我选择第一个盒子的另一项目的宽度总是变化。

I've got two select boxes. The first one is changing the entires of the second one. The second one always adjusts it's length to the longest of the actual entries. But it looks wuite ugly if the width always changes when i select another item of the first box.

是否可以设置第二个框为固定值的宽度,通过整体的最长的元素计算(无过滤)第二个框元素列表?在范围我可以计算最长元件的​​字符数。我可以调整这宽度不知何故?

Is it possible to set the width of the second box to a fixed value, calculated by the longest element of the whole (non-filtered) second box element list? In the scope I can calculate the number of characters of the longest element. Can I adjust this to the width somehow?

我已经尝试过(用于测试)

I already tried (for testing)

<select ... style="width:{{getMaxLength()}}px" > </select>

通过在范围方法getMaxLength()返回的字符数。但它并没有改变任何东西。

returning the number of characters by the method getMaxLength() in the scope. But it didn't change anything.

有没有人已经尝试呢?设置与NG-ATTR尺寸大小的工作,但它是这确实有助于我什么高度。

Did anyone already try this? Setting the size with ng-attr-size worked, but it's the height which does help me nothing.

我想AP preciate每一个提示或想法!
贾纳

I'd appreciate every hint or idea! jana

推荐答案

您可以使用 ngStyle

You can use ngStyle

从技术文档:

该ngStyle指令允许您设置CSS样式的HTML元素有条件地。

The ngStyle directive allows you to set CSS style on an HTML element conditionally.

例如:

<select ng-style="{'width': getMaxLength() + 'px'}"></select>

<大骨节病> Plunker

这篇关于AngularJS / CSS - 如何选择框的宽度设置为从$作用域的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆