Skip to content

Instantly share code, notes, and snippets.

@sunkay
Created January 19, 2014 16:47
Show Gist options
  • Save sunkay/8507387 to your computer and use it in GitHub Desktop.
Save sunkay/8507387 to your computer and use it in GitHub Desktop.
compare angular to meteor
//route
$routeProvider.when('/add', {templateUrl: 'partials/addDevice.html', controller: 'addDeviceController'});
//controller
.controller('addDeviceController', ['$scope', '$location', 'Devices',
function($scope, $location, Devices) {
$scope.add=true;
$scope.add = function(device){
if(!device) return;
// if device to add does not have and Id, create a random num id
if(device.id == undefined){
var randomnumber=Math.floor(Math.random()*1001);
device['id'] = randomnumber;
}
var newDevice = new Devices(device);
newDevice.$save(function success(){
// redirect to main screen
$location.path('#/');
}, function error(response){
console.log("Add Device Failed: " + response.status);
});
}
}])
WITH:
//Route
this.route('deviceNew', {
path: '/newDevice'
});
<template name="deviceNew">
<form class="main">
<div class="control-group">
<label class="control-label" for="name">Name</label>
<div class="controls">
<input name="name" type="text" value="" placeholder="Give a descriptive name"/>
</div>
</div>
</template>
Template.deviceNew.events({
// add a new device
'submit form': function(e){
e.preventDefault();
var device = {
name: $(e.target).find('[name=name]').val(),
os: $(e.target).find('[name=os]').val(),
owner: $(e.target).find('[name=owner]').val()
}
Logger.info("In deviceNew event: ",device,"deviceNew");
Meteor.call('insertDevice', device, function(error, id){
if(error)
throwError(error.reason);
Router.go('devicesList');
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment