ブートストラップ モーダル ダイアログを作成および管理するディレクティブがあります。
現在、コントローラーで保持されているブール値を監視するディレクティブがあります。コントローラーはこれを true に設定して、モーダル ダイアログを表示できます。
これはちょっと厄介なようです。より良い方法はありますか?
実際のディレクティブ:
<modal trigger="shouldDisplayModal" title="{{modalTitle}}"
message="{{modalMessage}}" positiveclick="okClicked()"
negativeclick="closed()"
positivelabel="Ok" negativelabel="Cancel"/>
ディレクティブのコントローラーのウォッチ:
// watch the trigger value. expected to be boolean
$scope.$watch('trigger',function(newValue, oldValue){
if (newValue)
{
// enable any disabled buttons
modalElem.find('button').removeClass('disabled');
// show the dialog
modalElem.modal('show');
}
else
{
// hide the dialog
modalElem.modal('hide');
}
});
これが実際の例です: http://jsfiddle.net/rabidgremlin/Ya96z/31/
更新:ページ上の複数のディレクティブに関するいくつかの問題を修正する修正例を次に示します: http://jsfiddle.net/rabidgremlin/sjbCJ/1/