Is it possible to call javascript remoting in a static resource?
I'm creating an AngularJS application, and to stick with best practices I would like to put my services in separate files. Theses services are used by angular controllers to get data out of Salesforce.
It works as expected when I define the service in the visual force page as follows:
<script>
salesCentral.factory('contentData', ['$q', '$rootScope', function($q, $rootScope) {
return function() {
var deferred = $q.defer();
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.MyJSRemoteController.getContentList}',
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;
}
}]);
</script>
However, when I include the exact same code from a static resource I get this error
TypeError: Cannot read property 'MyJSRemoteController' of undefined at Object.$VFRM.Util.getObject (https://cs2.salesforce.com/jslibrary/1383321200000/sfdc/VFRemote.js:119:364) ...
Does javascript remoting have to be defined directly inside the VisualForce Page?