How to bind a jQuery event to dynamic content with AngularJS -
basically in controller, i'm doing $http.get()
load html set "current view". issue can't figure out how rebind the jquery event new dynamic content.
right now, i've resorted somethign this:
$http.get('/someurl', {}).success(function(data){ $scope.detailedview = data; // here comes rebinding settimeout(function(){ // use jquery bind new content }, 1500); });
i've been looking solution, , related i've found points using directive. i've looked this, not know how directive used this.
note without timeout, bindings run before dynamic content in dom. i've tried finding similar hooking after $apply run have not found similar.
first should see if doing jquery can't done using angular.
here's simplistic version of directive can used:
<div ng-repeat="item in items" my-directive>item {{$index+1}}</div>
app.directive('mydirective', function ($timeout) { return function (scope, element, attrs) { $timeout(function () { /* element jquery object when jquery loaded in page before angular,*/ /* otherwise jqlite object has many of same methods jquery*/ element.css({ 'border': '1px solid green', 'margin': '10px 30px','padding':'5px'}); }, 0); } });
here's demo uses long timeout generate data repeated items use directive:
Comments
Post a Comment