<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>
<script src="jquery-1.9.1.min.js"></script>
</head>
<body>
<div ng-app="hd" ng-controller="ctrl">
设置:{{data}}
<br/>
获取:{{get.city}}
<br/><br/><br/><br/><br/>
<form method="post" action="">
商品:<input type="text" ng-model="goods.name"/><br/>
价格:<input type="text" ng-model="goods.price"/><br/>
<textarea name="goods"></textarea>
<input type="submit" />
</form>
</div>
<script>
var m=angular.module("hd",[]);
m.controller("ctrl",['$scope',function($scope){
$scope.data={'city':'xiamen'};
localStorage.setItem('data',angular.toJson($scope.data));//设置
$scope.get=angular.fromJson(localStorage.getItem('data'));//获取
$scope.goods={'name':'apple','price':10};
$('form').submit(function(){
$("[name='goods']").val(angular.toJson($scope.goods));//转化成字符串才会显示
return false;
});
}]);
</script>
</body>
</html>