What is the best practise to create a get/set property in an angular factory that will be set by a controller in view X and get by the same controller using view Y? Should I be using $rootScope like below?
Factory:
angular.module('start.services').factory('bluetoothFactory', ['$q', '$window', '$rootScope', function($q, $window, $rootScope) {
return {
connectedDeviceSet: function(device)
{
$rootScope.connectedDevice = device;
},
connectedDeviceGet: function()
{
return $rootScope.connectedDevice;
},
...
Controller:
angular.module('start.controllers',[]).controller('bluetoothCtrl', function($scope, $ionicModal, $timeout, bluetoothFactory)
{
...
$scope.list = function()
{
bluetoothFactory.list().then(function(data)
{
$scope.info = data;
if (data.length > 0)
{
bluetoothFactory.connectedDeviceSet = data[0];
}
},
function(error)
{
$scope.error = error;
});
};
$scope.readEPCForEncoding = function()
{
var device = bluetoothFactory.connectedDeviceGet;
....
}