Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 更改使用ng选项创建的选项组的标签_Angularjs_Angularjs Directive - Fatal编程技术网

Angularjs 更改使用ng选项创建的选项组的标签

Angularjs 更改使用ng选项创建的选项组的标签,angularjs,angularjs-directive,Angularjs,Angularjs Directive,我想使用angularjs select指令显示带有optionGroup的HTML select元素 但是,我希望控制optgroup label属性的值(每个标签都应该是相同的'--------------')。有没有办法做到这一点 也可能是在使用“0”的group by键时出现问题 可在以下位置找到一个可用的plunker: 编辑: 我希望selecto的外观如下所示: name 2 ------- name 1 ------- name 3 name 4 我没有看到任何选项从当前更改o

我想使用angularjs select指令显示带有optionGroup的HTML select元素

但是,我希望控制optgroup label属性的值(每个标签都应该是相同的'--------------')。有没有办法做到这一点

也可能是在使用“0”的group by键时出现问题

可在以下位置找到一个可用的plunker:

编辑:

我希望selecto的外观如下所示:

name 2
-------
name 1
-------
name 3
name 4

我没有看到任何选项从当前更改
optgroup
标签

编写自己的指令有一个变通方法。在您的
HTML

<select ng-model="selectedItem" 
            ng-options="item.text group by item.group for item in data" 
            optgroup-label="---"></select>

directive('optgroupLabel', function($timeout){
  return{
    link: function(scope, element, attrs){
      $timeout(function(){
          $(element).find('optgroup').each(function(i,e){
            $(e).prop('label', attrs.optgroupLabel);
          })
      },0);
    }
  }