Andrea Reginato
Published

The physical world meets the web

AngularJS directive to control your devices on web and mobile.

Work in progress447
The physical world meets the web

Story

Read more

Code

code.txt

Plain text
   angular.module('newProjectApp')
  .controller('MainCtrl', function ($scope, Device) {
    Device.all()
      .success(function(data) { $scope.devices = data })
      .error(function(data) { $scope.error = 'Unauthorized. Login first.' })
  });

code.txt

Plain text
   // Using Device API passing the Type ID in the query string
Device.all({ type: TYPE_ID }).success(function(devices) {
  scope.devices = devices;
})

// Using JSON filtering (this example uses underscore)
Device.all().success(function(devices) {
  scope.devices = _.where(devices, { type.id: TYPE_ID }
});

code.txt

Plain text
   
_.each(scope.devices, function(device) {
  $rootScope.$broadcast(
    'lelylan:device:template:update',
    { template: 'TEMPLATE_PATH', id: device.id}
  );
});

Github

https://github.com/lelylan/device-directive-ng/blob/master/dist/views/templates/default.html

Credits

Andrea Reginato

Andrea Reginato

1 project • 1 follower

Comments