javascript - AngularJs. Problems with ng-repeat -
i'm having 2 tables witch renders data trough angularjs, coming 2 c#-methods. tables structured same. first 1 below used searchfield , other 1 used basiclly render names. problem first 1 works perfect, other 1 not. , don't see problem. appreciated. // thanks!
here 2 tables. (the first 1 working)
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.18/angular.min.js"></script> <div ng-app="searchapp"> <div ng-controller="searchcontroller"> @*first table works*@ <span style="color: white">search:</span> <input data-ng-click="myfunction()" ng-model="searchtext"> <table style="color: white" id="searchtextresults"> <tr><th>name</th></tr> <tr ng-show="!!searchtext.length != 0" ng-repeat="friend in friends | filter:searchtext"> <td data-id="{{friend.id}}" data-ng-click="sendfriendrequest(friend.id)">{{friend.id.replace("ravenusers/","")}}</td> </tr> </table> @*does not work*@ <input type="button" value="get friends requests" data-ng-click="getfriendrequests()"> <table style="color: white"> <tr><th>friend requests</th></tr> <tr ng-repeat="friendrequest in friendrequests"> <td data-id="{{friendrequest.userwhowantstoaddyou}}" data-ng-click="acceptuserrequest(friendrequest.userwhowantstoaddyou)">{{friendrequest.userwhowantstoaddyou}}</td> </tr> </table> </div> </div>
here script
<script> var app = angular.module('searchapp', []); app.controller('searchcontroller', function ($scope, $http) { //get users seachfunction $scope.myfunction = function () { var result = $http.get("/home/getallusersexeptcurrentuser"); result.success(function (data) { $scope.friends = data; }); }; //get friendrequests other users $scope.getfriendrequests = function () { var result = $http.get("/home/getfriendrequests"); result.success(function (data) { $scope.friendrequests = data; }); }; }); </script>
the first script-function called myfunction
works perfect , data coming c#-method looks this:
[{"id":"ravenusers/one"},{"id":"ravenusers/two"},{"id":"ravenusers/three"}]
the second script-function called getfriendrequests
not work, , far can see there no difference between data passed here data passed myfunction
:
[{"userwhowantstoaddyou":"ravenusers/ten"},{"userwhowantstoaddyou":"ravenusers/eleven"}]
i'd suggest use then
instead of success
because $http
returns promise
.
if table doesn't "render" put breakpoint inside success function, console.log() data or check friendrequests
inside html template, e.g. using <div>{{ friendrequests | json }}</div>
, ensure got data response.
now not handle exceptions @ all.
example:
result.then(function(data) { console.log('got data') },function(error) { console.log('oh noes :( !'); });
related plunker here http://plnkr.co/edit/kzy8a3
Comments
Post a Comment