I have a button on my angular page on which I want to have a reset page. By reset, I mean returning the page to its original state, as if the user first accessed the page for the first time. I was thinking about going through copying, so I tried something like this:
$scope.orig = angular.copy($rootScope);
But it threw this mistake . I have several area variables and many controller variables. I do not want to save them individually. I thought it would be easier to copy the page to its original state, and then reset, retrieving the original version. But this does not seem to be an acceptable solution. Any ideas how to solve this problem?
Edit 1:
I tried Ben Felda's solution, but couldn't get it to work. Here is my controller code:
var app = angular.module('myApp',['ngRoute']);
var MyCtrl = function($route, $scope, $log, $http, $sce, $q, $filter) {
this.$route = $route;
this.$scope = $scope;
this.$log = $log;
this.$http = $http;
this.$sce = $sce;
this.$q = $q;
this.$filter = $filter;
this.ShouldAutoStart = false;
this.viewA = true;
this.viewB = false;
this.topButtonClicked = false;
this.showIDTable = false;
this.topRequest;
};
MyCtrl.prototype.reset = function() {
var _this = this;
console.log("route reloaded");
_this.$route.reload();
};
MyCtrl.prototype.getInfo = function() {
var _this = this;
_this.reset();
};
MyCtrl.$inject = ['$route','$scope', '$log', '$http', '$sce', '$q', '$filter'];
app.controller('MyCtrl', MyCtrl);
HTML:
<form ng-submit="dp.getInfo(dp.id)" class="form-inline">
<div class="form-group">
<div class="input-group">
<input type="text" ng-model="dp.id" class="form-control" required/>
</div>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
angular-route.js index.html. , ?