function in controller:
$scope.updateData = function () {
Words.fetch('update', $scope.randNum)
.error(function (data) {
console.log('update error: ' + data.message);
})
.success(function (data) {
$scope.board = data.settings.board;
$scope.tray = data.tray;
$scope.scores = data.pointsPerLetter;
$scope.totalScore = data.score.total;
console.log('update: ' + $scope.tray);
})
}
and the service function:
angular.module('wordService', [])
.factory('Words', function ($http) {
var id;
return {
fetch: function (call, num) {
id = num;
return $http.get('http://xxxxx');
},
sendUpdate: function (call, data) {
console.log('send update: ' + data)
return $http.post('http://xxxxx' + call, data);
}
}
});
Instead of using
ngAccess = angular.element(document.getElementById('ws')).scope();
to call ngAccess.updateData() or $scope.updateData
How can I incorporate this functionality within a service for easy access when needed, while still being able to update the scope from the controller? The current method is not compatible with browserify and does not have access to the scope yet.
Scenario: I want to click a button that triggers a function to update the scope. Note: The button is displayed on a canvas element. (shouldn't affect functionality as event listeners are still present).
Thank you in advance for your help!