2016-05-10 13 views
0

ng-modelはオプションと一致しないため、this SO questionから一時的に空の<select>オプションと関連する問題を解決しようとしています。次の行を使用するディレクティブ(リンクを使用)が表示されず、NGモデルに表示されないのはなぜですか?

ソリューションは完璧に動作しますが、私は直接そのHTMLをドロップしたときにのみ:

<option style="display:none" value="">(select)</option> 

私は「(選択)」のテキストを標準化し、その空のオプションを作成するために作成したディレクティブを持っています必要なとき:

空のデフォルト・option.js

(function() { 
    'use strict'; 

    function EmptyDefaultOptionDirective() { 
     return { 
      restrict: 'A', 
      link: function (scope, element) { 
       element.prepend('<option style="display:none" value="">(select)</option>'); 
      } 
     }; 
    } 

    angular.module('utils.empty-default-option', []) 
     .directive('emptyDefaultOption', EmptyDefaultOptionDirective); 
}()); 

HTMで使用されるとき、これは動作しません。 Lファイル:

context.html

<select class="form-control" 
     ng-model="context.contextChoice" 
     empty-default-option> 
      <option ng-repeat="choice in context.choices_data | orderBy:'id'">{{choice.first_name}} {{choice.last_name}}</option> 
</select> 

context.jsセットcontextChoice = ""ので、私はそれはそれはないと思います。 controllerAs: 'context'も)

私はまだ私の指示オプションが見られなかったことを意味する一時的な空白の空のオプションを得る。私はこれがリンク対コントローラ、おそらく、または物事がスキャンされるかチェックされるタイミングと関係があるように感じますが、私は答えを見つけるのに苦労しています。

読んでいただきありがとうございます!

+1

は '