Skip to content

Instantly share code, notes, and snippets.

@evilbloodydemon
Created October 28, 2013 06:14
Show Gist options
  • Select an option

  • Save evilbloodydemon/7192115 to your computer and use it in GitHub Desktop.

Select an option

Save evilbloodydemon/7192115 to your computer and use it in GitHub Desktop.
/// <reference path="_common.ts" />
module Devices {
export class Device {
constructor(
public ID: number,
public DeviceType: string,
public Vendor: string,
public Model: string,
public Platform: string
) { }
}
class DevicesListController {
name: string = "Shaitanama";
devices: Device[] = [];
static $inject = ['$scope', 'devicesService'];
constructor($scope: IScope, devicesService: DevicesService) {
this.devices = devicesService.getList();
$scope.vm = this;
}
}
class DevicesDetailController {
device: Device;
static $inject = ['$scope', '$routeParams', 'devicesService'];
constructor($scope: IScope, $routeParams, devicesService: DevicesService) {
this.device = devicesService.getByID($routeParams.id);
$scope.vm = this;
}
}
class DevicesService {
static $inject = ['$resource'];
constructor(
public $resource
) { }
getList(): Device[] {
return this.$resource('/devices', {}, {
query: {
method: 'GET',
isArray: true
}
}).query();
}
getByID(id: number): Device {
return this.$resource('/devices/view/?id=:id', {}, {
query: {
method: 'GET'
}
}).query({id: id});
}
}
angular
.module('demoApp.devices', ['ngResource'])
.service('devicesService', DevicesService)
.controller('DevicesListController', DevicesListController)
.controller('DevicesDetailController', DevicesDetailController);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment