This repository was archived by the owner on Sep 8, 2020. It is now read-only.
This repository was archived by the owner on Sep 8, 2020. It is now read-only.
Allow replace-transclude the sortable elements at link time #405
Open
Description
Code to reproduce issue:
app.js
var app = angular.module('App', ['ui.sortable']);
app.controller('MainCtrl', ['$scope', MainCtrl]);
function MainCtrl($scope) {
$scope.items = [
{id: 1, type: 'dog', name: 'galardo'},
{id: 2, type: 'cat', name: 'loossi'},
{id: 3, type: 'fish', name: 'sharkie'}
];
}
app.directive('myDirective', ['$compile', myDirective]);
function myDirective($compile) {
return {
restrict: 'EA',
replace: true,
//template: '<div ng-bind="item.name" item="item"></div>',
scope: {
type: "@",
item: "="
},
link: link
};
function link(scope, element, attrs) {
var view = $compile('<div ng-bind="item.name"></div>')(scope);
element.replaceWith(view);
}
}
index.html
<div ui-sortable ng-model="items">
<my-directive item="item" ng-repeat="item in items"></my-directive>
</div>
Console Error:
Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: item in items, Duplicate key: undefined:undefined, Duplicate value: undefined
http://errors.angularjs.org/1.4.7/ngRepeat/dupes?p0=item%20in%20items&p1=undefined%3Aundefined&p2=undefined
at http://localhost/angular-tests/lib/angular/angular.js:68:12
P.S: If we use template
property instead of link
function, there is no issue.
Cheers.