diff --git a/app/board.ctrl.js b/app/board.ctrl.js index 33788a7..ac017a9 100644 --- a/app/board.ctrl.js +++ b/app/board.ctrl.js @@ -3,29 +3,15 @@ angular.module('app').controller('BoardCtrl', Ctrl); - Ctrl.$inject = ['board']; - - function Ctrl(board) { + function Ctrl() { var vm = this; + vm.toggleAlarm = toggleAlarm; - vm.state = {}; + vm.state = { light: false, alarm: false }; - init(); - - vm.lightSwitchCallback = function (isOn) { - board.setLight(isOn).then(init); - }; - - vm.alarmSwitchCallback = function (isOn) { - board.setAlarm(isOn).then(init); - }; - - function init() { - board.getBoardState().then(function (state) { - vm.state = state; - }); + function toggleAlarm() { + vm.state.alarm = !vm.state.alarm; } - } })(); diff --git a/app/board.srv.js b/app/board.srv.js index da0455d..a6937ac 100644 --- a/app/board.srv.js +++ b/app/board.srv.js @@ -3,35 +3,22 @@ angular.module('app').service('board', Srv); - Srv.$inject = ['$q', '$window']; + Srv.$inject = ['$q']; - function Srv($q, $window) { + function Srv($q) { this.getBoardState = getBoardState; this.setLight = setLight; this.setAlarm = setAlarm; function getBoardState() { - var state = JSON.parse($window.sessionStorage.getItem('BOARD-STATE')); - return $q.when(state ? state : {}); + return { light: false, alarm: true }; } function setLight(isOn) { - var state = getBoardState(); - state.light = isOn; - saveState(state); - return $q.when(); - } - - function saveState(state) { - $window.sessionStorage.setItem('BOARD-STATE', JSON.stringify(state)); } function setAlarm(isOn) { - var state = getBoardState(); - state.alarm = isOn; - saveState(state); - return $q.when(); } } diff --git a/app/switch.cmp.js b/app/switch.cmp.js index 5c1e5c0..e8e42f1 100644 --- a/app/switch.cmp.js +++ b/app/switch.cmp.js @@ -4,23 +4,13 @@ var options = { templateUrl: 'app/switch.cmp.html', controller: Controller, - bindings: { - onChange: '=', - initial: '<' - } + bindings: {} }; function Controller() { - this.toggle = toggle; this.$onInit = $onInit; function $onInit() { - this.isOn = this.initial; - } - - function toggle() { - this.isOn = !this.isOn; - this.onChange(this.isOn); } } diff --git a/index.html b/index.html index 857941f..0c8fb51 100644 --- a/index.html +++ b/index.html @@ -2,20 +2,18 @@ - Ng1ts + Ng1comp
- Light: + {{ vm.state }} -
+

- Alarm: + Toggle alarm
@@ -29,7 +27,5 @@ - -