Created
November 28, 2013 21:18
-
-
Save kjellski/7698235 to your computer and use it in GitHub Desktop.
This is the communication setup between to controllers, one needs data from the other.
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
'use strict'; | |
var canvasDataServices = angular.module('CanvasDataServices', []); | |
canvasDataServices.service('CanvasDataService', ['$rootScope', '$q', | |
function CanvasDataService($rootScope, $q) { | |
var canvasDataService = {}; | |
canvasDataService.requestCanvasJSON = function() { | |
this.deferred = $q.defer(); | |
$rootScope.$emit('requestCanvasJSON'); | |
return this.deferred.promise; | |
}; | |
canvasDataService.responseCanvasJSON = function(canvasJSON) { | |
this.deferred.resolve(canvasJSON); | |
}; | |
return canvasDataService; | |
} | |
]); |
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
'use strict'; | |
var canvasControllers = angular.module('canvasControllers', []); | |
canvasControllers.controller('CanvasCtrl', ['$scope', '$rootScope', 'ImageDropService', 'CanvasDataService', | |
function($scope, $rootScope, ImageDropService, CanvasDataService) { | |
var canvasElement = document.getElementById('canvas-id'); | |
var canvasWidth = 580; | |
var canvasHeight = 400; | |
//console.log($scope); | |
var canvas = new fabric.Canvas('canvas-id'); | |
$rootScope.$on('requestCanvasJSON', function() { | |
console.log('requestedCanvasJSON') | |
CanvasDataService.responseCanvasJSON($scope.canvas.toJSON()); | |
}); | |
} | |
]); |
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
'use strict'; | |
var storyControllers = angular.module('storyControllers', []) | |
storyControllers.controller('StoryEditorCtrl', ['$rootScope', '$scope', 'Story', 'CanvasDataService', | |
function($rootScope, $scope, Story, CanvasDataService) { | |
$scope.story = NewStory(); | |
$scope.save = function() { | |
CanvasDataService.requestCanvasJSON().then( // <-- thanks for this nikolaj_a | |
function(json) { | |
$scope.story.json = json; | |
} | |
); | |
} | |
} | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment