Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling $http.get method from view with angularjs
    primarykey
    data
    text
    <p>i am trying to call a $http.get method to load contents of page (which is a list of email addresses). </p> <p>When my page loads, it continuously calling the http.get method, while i want to call it just once to load the email address and then store it in scope variable.</p> <p>My view code is </p> <pre><code>&lt;h2&gt;Members&lt;/h2&gt; &lt;!--&lt;div&gt;{{getTeamMembers()}}&lt;/div&gt;--&gt; &lt;div ng-repeat="member in teamParticipants"&gt; &lt;span&gt; &lt;/span&gt; &lt;span&gt;{{member}}&lt;/span&gt; &lt;/div&gt; </code></pre> <p>My controller class is </p> <p>Controllers.controller('FixedTeamController', function ($scope,$http,$location) {</p> <pre><code>$scope.addTeam = function() { $http.post('team', $scope.team). success(function(fixedTeam, status, headers, config) { //succcess }). error(function(fixedTeam, status, headers, config){ console.debug("error"); }); }; $scope.getTeamMembers = function(){ var teamUId = "12541254"; $http({method: 'GET', url: 'team/'+teamUId}). success(function(data, status, headers, config) { var members = []; $(data.listOfMembers).each(function(id,partcipantEmail){ $http({method: 'GET', url: 'users?email='+partcipantEmail}). success(function(participant, status, headers, config) { members.push("new member"); }) }); $scope.teamParticipants = members; }). error(function(data, status, headers, config) { console.debug("error"); }); }; }); </code></pre> <p>Code works fine, but it is calling the getTeamMembers() function continuously, so my question is that what should i do to call the function just once.</p> <p>Edit :: Added other method "addTeam" which is use to add new team members (it uses different view). By calling the function from inside controller partially solved the problem, but when now as i load the addTeam view, $scope.getFixedTeam() function also called, i don't want to call this function. How can i do that ? Regards,</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload