So I was trying to create something that will dynamically pull data from SalesForce and display it in my angular App. I created the .factory function below:
app.factory('getDocuments', ['$q','$rootScope', function($q, $rootScope){
return function (inputString) {
var deferred = $q.defer();
Visualforce.remoting.Manager.invokeAction(
'FO_Manager.getDocuments',
inputString,
function(result, event){
$rootScope.$apply(function(){
if(event.status) {
deferred.resolve(result);
} else {
deferred.reject(event);
}
})
},
{buffer: true, escape: true, timeout: 30000}
);
return deferred.promise;
}}]);
It runs great if I run it in the controller when the page loads getDocuments('a0N17000001NxjO').then(function(result){$scope.documents = result;},
function(error){$scope.error = result;});
The problem arises when I try to run it within my directive dynamically
app.directive('foSidenav',['getDocuments', function(getDocuments){
function linker($scope, element, attrs){
$scope.selectDocType = function(id)
{
alert('docId updated');
alert(id);
getDocuments(id).then(function(result){$scope.DocType = result;},
function(error){$scope.error = result;});
};
}
return{
restrict: 'E',
replace: true,
scope: {
info:'=',
DocType:'='
},
templateUrl:function(element,attr){
return attr.url;
},
link:linker
};}]);
Now the problem is when I run this code the alert show fine but then I get this error:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.
Any Idea how to get around this??
it turns out the error was elsewhere, this particular error did not prevent the script from running appropriately.
Some of my syntax was off!