Я использую директиву "draggable" для поддержки перетаскивания изображений. Однако, в соответствии с ролью пользователя, мне нужно отключить перетаскивание изображений для определенных групп пользователей. Я использовал следующий код.
<!--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>
, используя 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>
Есть ли другой подход, чтобы избежать двукратности кода?