css - 指令容器的高度为 0px,宽度为 0px - angularjs

标签 css angularjs angularjs-directive

当通过以下方式创建指令时,元素本身 ( <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/

相关文章:

css - 在 IE6 中使用 ">"选择器

css - Facebook 连接覆盖层被 Flash 覆盖

angularjs - 在 AngularJS 中将货币从美国转换为英国

javascript - ng-如果 Angular 不起作用

javascript - AngularJS 删除 href

javascript - AngularJS:通过服务更新将指令绑定(bind)到 Controller

javascript - Angular 指令调用父 Controller 函数

jquery - 特定颜色的小行显示在 anchor 标记中的图像下方

html - 如何保持图像背景图像静止?

angularjs - LinkedIn 爬虫可以读取 SPA 页面吗?