Hi, I have a controller, that performs an Ajax request with JWT authentication to a REST service:
angular.module("privacyideaApp")
.controller("tokenController", function ($scope, $http, $location,
tokenUrl, user) {
$scope.user = user.getUser();
$scope.getTokens = function () {
var auth_token = user.getAuthToken();
$http.get(tokenUrl, {
headers: {'Authorization': auth_token }
}).success(function (data) {
$scope.tokendata = data.result.value;
}).error(function (error) {
$scope.restError = error.result;
});
};
$scope.getTokens();
});
The response is stored in $scope.tokendata.
Now I can use it in my view like this. Mention the
ng-contoller="tokenController"
and iterate over the tokendata like
<tr ng-repeat="token in tokendata.tokens">
This is the complete view:
<div class="well" ng-controller="tokenController">
<div class="alert alert-info" ng-hide="restError">
This is your token {{ user.auth_token }}.
You are {{ user.username }}.
</div>
<div class="alert alert-danger" ng-show="restError">
Some error occurred.
{{ restError.error.message }}
Try to <a ui-sref="login">login</a>
</div>
<table class="table table-bordered table-responsive table-striped">
<thead>
<tr>
<th>serial</th>
<th>type</th>
<th>Active</th>
<th>counter</th>
<th>window</th>
<th>description</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="token in tokendata.tokens">
<td>{{ token.serial }}</td>
<td>{{ token.tokentype }}</td>
<td>{{ token.active }}</td>
<td>{{ token.count }}</td>
<td>{{ token.count_windows }}</td>
<td>{{ token.description }}</td>
<td>{{ token.failcount }}</td>
<td>{{ token.info }}</td>
<td>{{ token.maxfail }}</td>
<td>{{ token.otplen }}</td>
<td>{{ token.realms }}</td>
<td>{{ token.username }}</td>
<td>{{ token.user_id }}</td>
<td>{{ token.user_realm }}</td>
<td>{{ token.resolver }}</td>
<td>{{ token.resolver_type }}</td>
<td>{{ token.sync_window }}</td>
</tr>
</tbody>
</table>
</div>
Kind regards
Cornelius
Am 29.12.2014 um 10:19 schrieb Sasikumar Veeraiah:
> Hi all,
>
> How to store ajax result into one scope variable ? I need to use that
> result inside my controller.
>
> Eg:
>
> $http({
> url: '/app/demo/sample?a=getSamplesBySearchText',
> method: 'GET',
> params: {
> "searchText" : searchText
> }
> }).then(function (result) {
>
> *$scope.sampleResult=result;*
> console.log($scope.sampleResult); -----> Here i'm getting
> result eg: {name:"adams",age:"21"}
> });
>
> console.log(*$scope.sampleResult)* ----> *Undefined*
>
> If i try to print that result out side that method i'm getting
> undefined. I don't know why it's not printing those ajax result
> outside that method?
>
> Some one could help me to get those result and explain me why i'm not
> getting those values
>
>
>
> Thanks & Regards,
> Sasikumar.V
> --
> You received this message because you are subscribed to the Google
> Groups "AngularJS" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected]
> <mailto:[email protected]>.
> To post to this group, send email to [email protected]
> <mailto:[email protected]>.
> Visit this group at http://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/d/optout.
--
Cornelius Kölbel
[email protected]
+49 151 2960 1417
NetKnights GmbH
http://www.netknights.it
Landgraf-Karl-Str. 19, 34131 Kassel, Germany
Tel: +49 561 3166797, Fax: +49 561 3166798
Amtsgericht Kassel, HRB 16405
Geschäftsführer: Cornelius Kölbel
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
signature.asc
Description: OpenPGP digital signature
