当通过以下方式创建指令时,元素本身 ( <a-directive>
) 的高度为 0px,宽度为 0px。 jsfiddle
var myApp = angular.module('myApp', []).directive('aDirective', function () {
return {
template: '<div style="height:100px;width:100px;background-color:red;"></div>',
restrict: 'E',
link: function (scope, element, attrs) {
}
};
});
和 html:
<a-directive></a-directive>
如何让 html 元素具有其子维度?
编辑:
我刚刚在 fiddle 中看到,它有一个维度。但在我的元素中它通常没有。知道为什么会这样吗?
最佳答案
您可以为指令添加 CSS。示例:
a-directive {
display: block;
}
关于css - 指令容器的高度为 0px,宽度为 0px - angularjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30875180/