javascript - How to catch click event on remote loaded data and displayed with angularJS -


i include html data loaded ajax request , trigger click event on images in html data. understand wrong in spa world need displays data wysiwyg editor...

this code refactored version jquery:

          $http.get('help/help/gethelp', {                 params: {                     helpid: contentkey                 }             })                 .success(function(data) { 
                    if (data.success) {                          // viewdata html wysiwyg editor                         $scope.viewdata = data.viewdata;                          // here problem because images isn't in dom.                         angular.element('div#content').find('img').click(function () {                             // show image in gallery                         });                     } else {                         $scope.viewdata = "";                     }              }); 

but not function because images isn't in dom when trigger click event on them... best practice solve issue?

thanks!

i'm not sure viewdata represents, think going in wrong way.

when using angular, shouldn't loading html server (unless it's template, via templateurl).

instead server should return data display using template.

so images, example, might return server:

[   {     name: 'image1',     url: 'some/url.jpg'   },   {     name: 'image two',     url: 'some/other/url.jpg'   } ] 

then html have following:

  <img ng-src="image.url"         ng-click="showingallery(image)"         alt="{{image.name}}"         ng-repeat="image in images"/> 

and controller:

app.controller('imagecontroller', function($scope, imageservice){   imageservice.getimages().then( function(images){     $scope.images = images   });    $scope.showingallery = function(image){      //your gallery code here.    } }); 

i suggest reading more angular , s(ingle)p(age)a(pplication)s, trying use framework in way other how designed. means you'll hit lots of stumbling blocks , won't benefit power of great community surrounds it.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -