javascript - Using jquery from angular directive does not work -
i trying implement jquery-ui's sortable on elements inside ng-repeat.
problem : cannot sortable action on elements inside ng-repeat.
i've checked answers. code seems similar answers apparently work, code doesn't work
below html snippet:
<div class="container-fluid rt-widget-list-dim-adj"> <div my-dir> <div ng-repeat="widget in model.widgets" ng-switch="widget.widgettype"> <div ng-switch-when="header"> <ng-include src="'views/widget/widget-header.view.client.html'"> </div> <div ng-switch-when="image"> <ng-include src="'views/widget/widget-image.view.client.html'"> </div> <div ng-switch-when="youtube"> <ng-include src="'views/widget/widget-youtube.view.client.html'"> </div> </div> </div> </div>
my app.js:
(function(){ angular.module("myapp", ['ngroute', 'mydir']); })();
below custom directive:
(function () { angular .module("myapp", []) .directive("mydir", makesortable); function makesortable() { var directive = { restrict : 'ace', link : linker }; function linker(scope, element, attrb) { element.sortable(); } return directive; } })();
element in linker function args not jquery, jqlite wrapper. if want apply jquery, try this:
$j(element[0]).sortable();
Comments
Post a Comment