Angularjs and spark

I am trying to make a basic UI for spark using angularjs.
I tried to use this example from this topic :

to get a variable but with no success.
Did anyone tried anything similar, or have some experience with angular and can check it?

Here is my code on jsfiddle :

I havent done it using Resources… but I have done it via $http.

So in your Controller declare it like this:

var MainCtrl = function ($scope, $location, $route, $http) {
     //Your code here

Here is a POST example:

    method: 'POST',
    url: '' + SparkDeviceID + '/Trigger?access_token=' + SparkAccessToken,
    data: $.param({args: argsData}),
    headers: {'Content-Type': 'application/x-www-form-urlencoded'}
.success(function(data, status, headers, config) {    	 
.error(function(data, status, headers, config) {
    alert('Error' + data);

Here is a GET:

    method: 'GET',
    url: '' + SparkDeviceID + '/DoorStatus' + '?access_token=' + SparkAccessToken,
.success(function(data, status, headers, config) {	 
    if (data.result == 0) 
	$scope.State = 'Closed';
	$scope.State = 'Open';			
.error(function(data, status, headers, config) {
    alert('error ' + data);

There is no reason why a Resource wont work, but I’ll have to look later tonight and see why. I figured I just post some $http code that works.



Thanks for your reply Carsten4207.
I’ll check it.

If you look at the console you’ll notice it’s complaining about the ngResource. Turns out you need to load that externally. If you add this link ( to the external resources, you should at least be able to retrieve a variable. Then you’ve got to figure out the dependencies of $interval.

Is there a specific need that requires you to use variables? Instead of polling for data, you could have the Core publish data every second.

1 Like

I didn’t know there was a console to jsfiddle… Thank you.
I thought it would be easier to retrieve variable, I would check if listening to an event is easier.

1 Like