-
Notifications
You must be signed in to change notification settings - Fork 443
Allow replace-transclude the sortable elements at link time #405
Comments
Great finding!!! |
Hi, @thgreasi
No it doesn't. Using
Yes , here it is. Actually this issue raised in Cheers |
See what happened in html source when we sorting one element in <div ui-sortable="" ng-model="items" class="ng-pristine ng-untouched ng-valid ng-isolate-scope ui-sortable">
<!-- ngRepeat: item in items track by $index -->
<my-directive item="item" type="item.type" ng-repeat="item in items track by $index" class="ng-scope ng-isolate-scope"></my-directive>
<!-- end ngRepeat: item in items track by $index -->
<my-directive item="item" type="item.type" ng-repeat="item in items track by $index" class="ng-scope ng-isolate-scope"></my-directive>
<!-- end ngRepeat: item in items track by $index -->
<my-directive item="item" type="item.type" ng-repeat="item in items track by $index" class="ng-scope ng-isolate-scope"></my-directive>
<!-- end ngRepeat: item in items track by $index -->
<div ng-bind="item.name" class="ng-binding ng-scope ui-sortable-handle">sharkie</div>
<div ng-bind="item.name" class="ng-binding ng-scope ui-sortable-handle">galardo</div>
<div ng-bind="item.name" class="ng-binding ng-scope ui-sortable-handle">loossi</div>
</div> |
It seems that its a problem with the replacement of the original element... I saw that you use a "type" attribute. If that's your main use case, have |
@thgreasi Thanks, I already checked that. Actually my main reason of using But may I ask you how your Actually I have a list like this: var data = [
{id: 1, type: 'chapter', title: 'chapter 1'},
{id: 1, type: 'lecture', title: 'lecture 1-1'},
{id: 2, type: 'lecture', title: 'lecture 1-2'},
{id: 2, type: 'chapter', title: 'chapter 2'},
...
]; and a wrapper directive, something like that: app.directive('curriculum', ['$compile', curriculum]);
function curriculum($compile) {
return {
restrict: 'EA',
replace: true,
scope: {
type: "@",
item: "="
},
link: link
};
function link(scope, element, attrs) {
var view = $compile('<curriculum-'+ scope.type +' item="item"></curriculum-' + scope.type + '>')(scope);
element.replaceWith(view);
}
}
app.directive('curriculum-chapter', [curriculumChapter]);
function curriculumChapter() {
return {
...
template: '/templates/chapter.tpl.html'
...
}
}
app.directive('curriculum-lecture', [curriculumLecture]);
function curriculumLecture() {
return {
...
template: '/templates/lecture.tpl.html'
...
}
} So is it possible to use Thanks in advance. |
Unfortunate I thinks angularjs should allows nested directive with |
With the |
As you saw transclusions with |
My experience on a similar implementation convinced me that ng-include was On Mon, Nov 9, 2015, 16:25 Soheil Samadzadeh [email protected]
|
@thgreasi, this was a good discussion. and thank you. Finally I ended up with this solution: app.directive('curriculum', curriculum);
function curriculum() {
return {
restrict: 'EA',
replace: true,
template: '<div ng-include="templateUrl" include-replace></div>',
link: link,
scope: {
type: '@',
item: '='
}
};
function link(scope) {
scope.templateUrl = "/templates/curriculum-" + scope.type + ".tpl";
}
}
app.directive('includeReplace', curriculum);
function includeReplace() {
return {
require: 'ngInclude',
replace: true,
restrict: 'A',
link: function (scope, el) {
el.replaceWith(el.children());
}
};
} <curriculum ng-repeat="item in curriculum" type="[[item.type]]" item="item" ></curriculum> It may be good solution for cases that only depends on templates. And I think we should get back and focus on main issue of Thank you very much |
I'm glad that it worked for you 👍 |
I also changed the title to what I think better describes the problem. My opinion is that is not the linking that is causing the problem (since your directive and tg-dynamic-directive also have link functions) but the fact that we are replacing the sortable items that are generated by the ng-repeat. |
👍 |
Code to reproduce issue:
app.js
index.html
Console Error:
P.S: If we use
template
property instead oflink
function, there is no issue.Cheers.
The text was updated successfully, but these errors were encountered: