画像のドラッグをサポートするために「ドラッグ可能」ディレクティブを使用しています。ただし、ユーザーの役割に応じて、特定のユーザー グループに対して画像のドラッグを無効にする必要があります。次のコードを使用しました。
<!--draggable attribute is used as handle to make it draggable using jquery event-->
<li ng-repeat="template in templates" draggable id="{{template._id}}" type="template" class="template-box">
<!-- Images and other fields are child of "li" tag which can be dragged.-->
</li>
メソッドdragSupported
はテンプレート スコープ内にあり、true
またはを返しますfalse
。によって返される各値<li>
を使用して、2 つの大きな重複要素を作成したくありません。つまり、これを解決するための次のアプローチを探しているわけではありません。ng-if
dragSupported()
<!--draggable attribute is used as handle to make it draggable using jquery event-->
<li ng-if="dragSupported() ==true" ng-repeat="template in templates" draggable id="{{template._id}}" type="template" class="template-box">
<!-- Images and other fields are child of "li" tag which can be dragged.-->
</li>
<!--remove "draggable" directive as user doesn't have permission to drag file -->
<li ng-if="dragSupported() !=true" ng-repeat="template in templates" id="{{template._id}}" type="template" class="template-box">
<!-- Images and other fields are child of "li" tag which can be dragged.-->
</li>
コードの重複を回避する他の方法はありますか?