Skip to content

Instantly share code, notes, and snippets.

View mgonto's full-sized avatar

Martin Gontovnikas mgonto

View GitHub Profile
@mgonto
mgonto / track.html
Last active December 18, 2015 01:19
Angularytics Track Event filter
<label>Click here to submit buddy</label>
<input type="submit"
ng-click="doSomething() | trackEvent:'Home Category':'Button clicked'" />
@mgonto
mgonto / app.js
Last active December 18, 2015 01:19
Angularytics Bootstrap
angular.module('sample-app', ['angularytics'])
.config(function(AngularyticsProvider) {
AngularyticsProvider.setEventHandlers(['Console', 'Google']);
})
.run(function(Angularytics) {
Angularytics.init();
});
@mgonto
mgonto / restangular.js
Created May 24, 2013 21:32
Restangular impl
// Assigning promise
// GET /api/v1/users
var users = Restangular.all('users').getList();
// GET /api/v1/users/123
var user = Restangular.one('users',123).get();
// Assigning value
// GET /api/v1/users
Restangular.all('users').getList().success(function(users) {
@mgonto
mgonto / resource.js
Created May 24, 2013 21:27
$resource impl
var userResource = $resource('/users/:userId', {}, {
getList: {method: 'GET', params: {}, isArray: true},
get: {method: 'GET', params: {}, isArray: false},
});
var users = userResource.getList();
var user = userResource.get({userId: 123})
// Later in the code
var carResource = $resource('/users/:userId/cars/:carId', {}, {
@mgonto
mgonto / directive.js
Created May 19, 2013 02:01
directive proposed
module.directive('pie', function () {
return {
replace: true,
restrict: 'EA',
scope: {type: '@', data:'='},
templateUrl: "/js/test/angular/partials/pie.html",
controller: ['$scope', '$routeParams', '$element', '$filter', function($scope, $routeParams, $element, $filter) {
$scope.$watch('data', function() {
if (_.isUndefined($scope.data) || _.isNull($scope.data) || $filter('isZeroData')($scope.data)) {
@mgonto
mgonto / firstTab.html
Created May 19, 2013 02:00
firstTab.html
<div>
<h1>First Tab</h1>
<input type="text" ng-model="query.searchText" />
<pie data="data.valuesData | forPie" type="valuesPie" />
</div>
@mgonto
mgonto / proposedApp.js
Created May 19, 2013 01:59
Proposed app.js
'use strict';
/**
* Application start point.
*
* Note, we use minifyer, so all dependencies should be explicitly defined with ['<dependency>',
* function(<dependency>) {}];
*/
var module = angular.module('example',
[ 'restangular', 'ngResource']).config(
@mgonto
mgonto / proposed.html
Created May 19, 2013 01:57
HTML Proposed
<html>
<head>
<!-- Include here Styles and AngularJS scripts-->
</head>
<body>
<div class="container" ng-app="example" ng-controller="MainCtrl" ng-cloak>
<header>
<div>This is the common headers for all of the tabs of this little app</div>
</header>
<!-- This is the div that will change when the URL changes via the $routeProvider-->
@mgonto
mgonto / restangularPromise.js
Created May 3, 2013 06:19
Restangular Promise Enhanced
var buildings = Restangular.all("buildings").getList();
// New promise after adding the new building
// Now you can show in scope this newBuildings promise and it'll show all the buildings
// received from server plus the new one added
var newBuildings = buildings.push({name: "gonto"});
var newBuildingsSame = buildings.call("push", {name: "gonto"});
// This is a promise of a number value. You can show it in the UI
@mgonto
mgonto / enhancedPromises.js
Last active December 16, 2015 22:28
Enhanced Promises
function enhancePromise(promise, isCollection) {
promise.call = angular.bind(promise, promiseCall);
promise.get = angular.bind(promise, promiseGet);
return promise;
}
function promiseCall(method) {
var deferred = $q.defer();
var callArgs = arguments;
this.then(function(val) {