2016-11-25 38 views
2

ajaxを介してロードされた(そして後にキャッシュされる)オプションのセットで構成されるselectに幾分一般的なディレクティブがあります。'select'要素を含むディレクティブ内でカスタムオプションを継承する

このディレクティブがどこで使用されているかによって、いくつかのオプションを指定する必要があります。ディレクティブされた状態で

<select-directive ng-model="model"> 
    <option value="x">custom option</option> 
</select-directive> 

{ 
      restrict: 'E', 
      scope:{ 
       ngModel: '=' 
      }, 
      transclude:true, 
      template:[ 
       '<select class="tipos" ng-model="ngModel">', 
        '<ng-transclude></ng-transclude>', 
        '<option ng-selected="ngModel === item.tipo" ng-repeat="item in ::tiposDoc track by item.tipo" value="{{::item.tipo}}" title="longer description">', 
         'description', 
        '</option>', 
       '</select>' 
      ].join(''), 
      link: function(scope){ 
       $http.get('viewApp/viewCtrl.php/getTipos',{cache:true}) 
        .then(function(response){ 
         var resp = response.data; 
         if(!resp.success){ 
          console.log(resp.log); 
          alert(res.msg); 
          return false; 
         } 
         scope.tiposDoc = resp.result; 
        }); 
      } 
     } 

しかし、カスタムオプションを選択要素に表示されません私はこのようなオプションをtransclude可能性が考えていました。何か不足していますか?これは何らかの形で可能ですか?

答えて

1

どうやらng-includeタグの競合、私は使用して終了この問題を回避するには、幸運にもそれng-transclude属性を持つoptgroup、を含むました仕事:

Maximusの回答もうまくいきましたが、カスタムオプションと一緒に機能するようにはできませんでした。

1

あなたはこのようにそれを行うことができます。角度のselectディレクティブを使用して何らかの方法で

link: function(scope, element, attrs, ctrls, transclude){ 
    var html = transclude(); 
    element.find('select').append(html); 
} 
+0

私は別のアプローチを使用して終了しましたが、これは念頭に置くために完全に有効な代替手段です、ありがとう! – Sebastianb

+0

@Sebastianb、あなたも大歓迎です:) –

関連する問題