angularjs - Refresh data on click outside controller in angular -


i trying grasp idea behind angular , ran first obstacle involving accessing data outside scope (the app?)

here simple example of i'm trying do:

html:

<div class=logo>     <a href='/refresh'>refresh</a> </div> <div ng-app ng-controller="threadslist"> <div class='thread_list_header'>     <table class='thread_list_table'>     <tr class='table_header'>         <!--1--><td class='table_c1'></td>         <!--2--><td class='table_c2'>{{name}}</td>         <!--3--><td class='table_c3'>cliq</td>         <!--4--><td class='table_c4'>last poster</td>         <!--5--><td class='table_c5'><a class="clickme">refresh</a></td>     </tr></table> </div> <table class='thread_list_table' >     <tr class="thread_list_row" ng-repeat="user in users">                 <!--1--><td class='table_options table_c1'></td>         <!--2--><td class='table_subject table_c2' title="">{{user.subject}}</td>                 <!--3--><td class='table_cliq table_c3'></td>                 <!--4--><td class='table_last table_c4'><span class="thread_username"><a href=#>{{user.username}}</a></span></td>                 <!--5--><td class='table_reply table_c5'><abbr class="thread_timestamp timeago" title=""></abbr></td>     </tr>     </table> </div> 

js:

function threadslist($scope, $http) {   $scope.name = 'ricky';    // initialising variable.   $scope.users = [];      $http({     url: '/cliqforum/ajax/ang_thread',     method: "post",   }).success(function (data) {       console.log(data);     $scope.users = data;   });   // getting list of users through ajax call.   $('.table_header').on('click', '.clickme', function(){         $http.get('/cliqforum/ajax/ang_thread').success(function(data){              $scope.users = data;         });      }); } 

this part can't figure out. logo supposed clear whatever filter on current 'user' data. however, sits outside scope (and imagine shouldn't expand scope entire page?)

i have read scope.$spply can't quite figure out i'm supposed do:

 $('.logo').on('click', 'a', function() {          scope.$apply(function () {             $scope.users = data;         });     }); 

it's not quite necessary way...i correct!

thanks!

and imagine shouldn't expand scope entire page?

why not? that's way it. include logo scope , can access application, , use ng-click add click handler.

in fact, should avoid using jquery click handlers within application. transform javascript so:

$scope.tableheaderclick = function() {     $http.get('/cliqforum/ajax/ang_thread').success(function(data){         $scope.users = data;     });    }); 

then update html so:

<tr class='table_header' ng-click="tableheaderclick()"> 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -