Skip to content

Instantly share code, notes, and snippets.

@rePassante rePassante/main
Created Jun 3, 2013

What would you like to do?
AngularJS - Shared Data Services & Handling Page Refreshes
<!-- Check For Customer Data In sharedData -->
if (sharedData.getNewlyAddedCustomer() != null) {
<!-- The Data Exists In sharedData, add it to $scope and Proceed Normally -->
$scope.newlyAddedCustomerRequest = sharedData.getNewlyAddedCustomerRequest();
} else {
<!-- The Data DOES NOT Exist In sharedData, Let's check the hash and see if we can re-fetch -->
var path = $location.path();
var splitPath = path.split("/");
<!-- When we eval our split path we can eval to see if we have info after the route
if (splitPath.length > 2) {
<!-- We have the info we need so we can re-fetch the customer details by the Id in the hash -->
$scope.responseFromServer = MockDataResource.get({ id: splitPath[2] },
function (response) {
//Success - Re-Add To sharedData & $scope
$scope.newlyAddedCustomerRequest = sharedData.getNewlyAddedCustomerRequest();
function (error) {
console.error("Unable to fetch Customer Details");
} else {
<!-- The required info isn't present in the hash, let's go back to our customers page gracefully -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.