【问题标题】:The link function in the directive does not draw a border AngularJS指令中的链接函数不画边框AngularJS
【发布时间】:2017-11-23 21:29:59
【问题描述】:

嘿,我正在尝试为使用 ng-repeat 列出的项目制作边框,我使用了链接功能,但我不想工作,我不绘制边框,它只会创建破折号。

指令

    (function(){
  angular.module('app')
    .directive('myDirective', function(){
    return {
      restrict : 'E',
      scope : {
        list : '='
      },
      template: '<div class="dire" ng-repeat="item in list">{{item}}</div>', 
      link: function($scope, $element, $attrs) {
        $element.addClass('active');
      }
    }
  }); 

演示 https://codepen.io/Turqus/pen/mqKVWY?editors=1111

【问题讨论】:

标签: angularjs


【解决方案1】:

您的 div 元素是一个内联对象。您需要使用display: block; 使其成为blockinline-block元素。这不取决于您的指令。这是 CSS 问题。

.active {
  border: 1px solid red;
  font-size: 50px;
  box-sizing: border-box;
  background-color: yellow;
  color: red;
  display: block;
}

>> CodePen

【讨论】:

  • 谢谢!我有疑问,如果我想用 addClass 为子 div 创建链接功能怎么办??
  • 是的,我知道,但我只问未来,你知道.. :D 如果...发生了什么:P
猜你喜欢
  • 2014-03-11
  • 2014-07-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-09
  • 1970-01-01
  • 2015-03-28
  • 1970-01-01
相关资源
最近更新 更多