Convert scope value tofrom Json

Description

The following code shows how to Convert scope value tofrom Json.

Example


<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
</head><!--  w w  w.j a v  a  2s. c o  m-->
<body>
  <div ng-app ng-controller="x">
</div>
<script type='text/javascript'>
function x($scope) {
    $scope.Model = {};
    $scope.Model.a = 'asdf';
    $scope.Model.b = 'asdffff';
    $scope.Model.c = true;

    console.log(angular.fromJson(angular.toJson($scope.Model)));
}
</script>
</body>
</html>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Example »




Controller
Directives
Expression
Filter
Form
Inject
Scope
Server
Style
Template
Utilities