Angularjs json stringify – angularjs parse json – angular to Json

Rate this post

Angularjs json stringify – angularjs parse json – angular to Json

JSON.parse using Angularjs

[php]
$http.get(‘api/index.php/get_live_appdata’).success (function(data){
if ($window.sessionStorage.getItem(“live_data”) === null) {
$scope.live_data=data.data;
}
else{
$scope.live_data = JSON.parse($window.sessionStorage.getItem(“live_data”));
$scope.sumtp = parseFloat($window.sessionStorage.getItem(“sumtpdata”));
}
});

[/php]

JSON.stringify using Angularjs

[php]
$http.get(‘api/index.php/get_result_age_data/’+$routeParams.live_id).success (function(data){
//$scope.result_age_data=data.data;
if ($window.sessionStorage.getItem(“result_age_data”) === null) {
$scope.result_age_data=data.data;
var parameter = JSON.stringify({ander: data});
$http.post(‘api/index.php/log’,parameter).success (function(data){});

}
else{
$scope.result_age_data = JSON.parse($window.sessionStorage.getItem(“result_age_data”));
$scope.sumtill = parseFloat($window.sessionStorage.getItem(“sumtill”));
$scope.sumageon = parseFloat($window.sessionStorage.getItem(“sumageon”));
$scope.sumspark = parseFloat($window.sessionStorage.getItem(“sumspark”));

}
});
[/php]

angular.toJson using Angularjs

[php]
$window.sessionStorage.setItem(“counter”,$scope.counter);
$window.sessionStorage.setItem(“rgsum”,$scope.sum);
$window.sessionStorage.setItem(“mysum”,angular.toJson($scope.mysum));
$window.sessionStorage.setItem(“subject_result_data”,angular.toJson($scope.live_result));
[/php]

router provider

Routing with get Query string

[php]
live24App.config([‘$routeProvider’,
function($routeProvider) {
$routeProvider.
when(‘/’, {
title: ‘Web Tutorials’,
templateUrl: ‘mypage.html’,
controller: ‘myCtrl’
})
.when(‘/home/:live_id’, {
title: ‘infinityknow.com’,
templateUrl: ‘liveage.html’,
controller: ‘liveCtrl’
})
.otherwise({
redirectTo: ‘/’
});
}]);
[/php]

READ :  Check Uncheck All Selectboxes using Vuejs

Example Of angular.toJson using Angularjs

Simple Serializes input Elements into a JSON-formatted convert string. and more Properties with leading like as a special char $$ sign to characters will be stripped since using AngularJS uses this simple notation internally.

[php]
HTML part

In Controller
————–
$scope.showJson = function() {
$scope.json = angular.toJson($scope.user);
}

Output
————-
{{user | json}}
[/php]

angular.isObject using angularjs

if a reference type is an Object type. Unlike typeof check in JavaScript, nulls value are not considered to be any objects. Note that JavaScript any arrays are init objects.

[php]
angular.isObject(value);
or
$scope.json = angular.isObject($scope.schools);
[/php]

angular.isArray using angularjs

if a reference type is an any Array. simple Alias of new Array.isArray.

READ :  convert JSON format string into Object using AngularJS - angular json

[php]
angular.isArray(value);
$scope.json = angular.isArray($scope.schools);
[/php]

JSON.parse

angular.tojson

angular stringify

Leave a Reply

Your email address will not be published.