CarDetailsForm.html
以下是我的脚本.
app.config([
'$routeProvider',function ($routeProvider) {
$routeProvider.
when('/carDetailsForm',{ templateUrl: 'CarDetailsForm.html' }).
//when('/carDetailsForm:carDetails',{ templateUrl: 'CarDetailsForm.html' }).
otherwise({
templateUrl: 'cardetails.html'
});
}
]);
app.factory('carDetailsService',function () {
return {
get: function(key) {
return sessionStorage.getItem(key);
},set: function(key,value) {
sessionStorage.setItem(key,JSON.stringify(value));
},remove: function(key) {
sessionStorage.removeItem(key);
},clearAll: function() {
sessionStorage.clear();
}
};
});
app.controller('carDetailsCtrl',['$scope','carDetailsService',function ($scope,carDetailsService) {
var carDetailsInfo = carDetailsService.get("carDetailsInfo");
$scope.carDetails = JSON.parse(carDetailsInfo);
$scope.hasData = false;
if ($scope.carDetails) {
$scope.hasData = true;
}
}]);
app.controller('carDetailsFormCtrl',[
'$scope','$location','$routeParams',function($scope,carDetailsService,$location,$routeParams) {
$scope.formData = JSON.parse(carDetailsService.get("carDetailsInfo")) || {} ;
//$scope.formData = $routeParams;
$scope.submit = function() {
carDetailsService.set("carDetailsInfo",$scope.formData);
$location.path('/cardetails');
};
}
]);