A simple (seeming) question - I'm trying to do a simple sanity check in my AngularJS controller to make sure my $ resource is actually created as such. This is a fairly large application, but for example:
.factory('AccountSearchService_XHR', ["$resource", function($resource) { var baseUrl = "http://localhost\\:8081/api/:version/accounts/:accountNumber"; return $resource(baseUrl, { version: "@version", accountNumber: "@accountNumber" }, { get: {method: 'GET', isArray: false} }); }]);
Then later in the controller:
$scope.accountObj.currentAccount = AccountSearchService_XHR.get({ version: "v1", accountNumber: "1234" }, function(result) {... etc etc});
The call to my API works fine, everything returns data as I expect, but I would like to check if there is a $scope.accountObj.currentAccount
resource before trying to make a .get
call (note the super important capital) R ').
When I check the $scope.accountObj.currentAccount
object in the chrome debugger, it looks like this:
Resource {accountHolderName: Object, socialSecurityNumer: null, birthDate: "05/14/1965", maritalStatus: ...}
Due to some complexity of my setup, although sometimes it is overwritten as a regular object ( typeof
returns "object"
), but checking it in the debugger confirms that it has lost its Resource
status.
So, does anyone know how to check if it is a $ resource? Almost like typeof $scope.accountObj.currentAccount
returns "Resource"
? Or maybe the best way is best to ensure that everything connects everything that is appropriate and respectable?
All the SO articles I've seen while searching revolve around actual Jasmine testing.
Thanks in advance.