[英]How to find the current width of an element in Angular if an element is removed
Assume that the below code is a horizontal navbar: 假定以下代码是水平导航栏:
HTML: HTML:
<ul>
<li ng-repeat="navItem in totalNavItems">{{name}}</li>
</ul>
css: CSS:
ul,li {
display:inline-block;
}
And it gets the values from this json data: 然后从此json数据获取值:
var totalNavItems = [{"name":"Item 1"},{"name":"Item 2"},{"name":"Item 3"}];
Once the page loads, it populates the DOM with the all the items in the array. 页面加载后,它将使用数组中的所有项目填充DOM。 Then I get the width of the parent element like so (yes, I'm using jQuery also):
然后我像这样获得父元素的宽度(是的,我也在使用jQuery):
$(element).parent().width();
Then, for instance I take away one of the items after taking the above width measurement. 然后,例如,在进行上述宽度测量后,我拿走了其中一项。
totalNavItems = totalNavItems.slice(0,2);
Now, how do I get the updated width value of the parent? 现在,如何获取父级的更新宽度值?
(I'm writing the angular codes inside a directive link, btw) (我在指令链接中写了角度代码,顺便说一句)
Try this may be it will work:- 试试这个可能会起作用:-
totalNavItems = totalNavItems.slice(0,2).then(function () {
$(element).parent().width();
});
use call back .then
function. 使用回调
.then
函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.