Created
June 6, 2017 16:29
-
-
Save chadwithuhc/296185ed7972088805c89fac48d3d9c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
'use strict' | |
angular.module('app') | |
.service('houseService', function () { | |
this.houses = [ | |
{id: 1, name: 'Spacious two bedroom', address: '10 Main St'}, | |
] | |
this.seedHouses = function() { | |
console.log('localStorage', window.localStorage) | |
if (!window.localStorage.getItem('houses')) { | |
window.localStorage.setItem('houses', JSON.stringify(this.houses)) | |
console.log('Created fake houses', JSON.parse(window.localStorage.houses)) | |
} | |
} | |
this.seedHouses() | |
this.getHouses = function() { | |
return JSON.parse(window.localStorage.getItem('houses')) | |
} | |
this.setHouses = function(houses) { | |
window.localStorage.setItem('houses', JSON.stringify(houses)) | |
return true | |
} | |
this.addHouse = function (house) { | |
let houses = this.getHouses() | |
houses.push(house) | |
house.id = houses.length | |
this.setHouses(houses) | |
return house | |
} | |
this.findById = function (id) { | |
let houses = this.getHouses() | |
return houses.find(house => house.id == id) | |
} | |
}) | |
}()); | |
// (function() { | |
// 'use strict' | |
// | |
// angular.module('app') | |
// .service('houseService', function () { | |
// this.houses = [ | |
// {id: 1, name: 'Spacious two bedroom', address: '10 Main St'}, | |
// ] | |
// | |
// this.addHouse = function (house) { | |
// this.houses.push(house) | |
// house.id = this.houses.length | |
// return house | |
// } | |
// | |
// this.findById = function (id) { | |
// return this.houses.find(house => house.id == id) | |
// } | |
// }) | |
// | |
// }()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment