0
我在文檔中有一系列LI元素......他們需要根據項目的數量和容器的寬度來調整其寬度......如何從此指令中檢索父容器的寬度?AngularJS調整爲父級?
var MyApp = angular.module('myApp', [])
.directive('resize', function() {
return {
restrict: 'A',
scope: {},
link: function(scope, elem, attrs) {
// TODO: Resize according to percentage of parent???
elem.css('width', '400px');
}
};
});
嘗試用element.parent()寬()(你應該有包括jQuery的),但可能是你必須表現出更多的代碼 – Whisher 2014-11-02 20:02:38
我沒有使用jQuery .. 。我的印象是,Angular會採用輕量級的jQL版本,如果不使用? – 2014-11-02 20:03:59
elem.parent()[0] .offsetWidth似乎工作... – 2014-11-02 20:05:41