Skip to content

Instantly share code, notes, and snippets.

View mgonto's full-sized avatar

Martin Gontovnikas mgonto

View GitHub Profile
// bad
if (currentUser) {
function test() {
console.log('Nope.');
}
}
// good
if (currentUser) {
var test = function test() {
@mgonto
mgonto / app.js
Last active December 15, 2015 07:49
var module = angular.module('basicsite',
['ngResource']).
config(['$routeProvider', function ($routeProvider) {
$routeProvider.
when('/',
{templateUrl: '/js//views/main.html', controller: 'MainCtrl'}).
when('/sports',
{templateUrl: '/js/views/sports.html', controller: 'SportsCtrl'}).
when('/players',
{templateUrl: '/js/views/players.html', controller: 'PlayersCtrl'}).
@mgonto
mgonto / directives.js
Created March 23, 2013 03:20
Footer Angular
module.directive('footer', function () {
return {
restrict: 'A', //This menas that it will be used as an attribute and NOT as an element. I don't like creating custom HTML elements
replace: true,
templateUrl: "/js/directives/footer.html",
controller: ['$scope', '$filter', function ($scope, $filter) {
// Your behaviour goes here :)
}]
}
});
@mgonto
mgonto / directives.js
Last active December 15, 2015 07:49
Header angular
module.directive('header', function () {
return {
restrict: 'A', //This menas that it will be used as an attribute and NOT as an element. I don't like creating custom HTML elements
replace: true,
scope: {user: '='}, // This is one of the cool things :). Will be explained in post.
templateUrl: "/js/directives/header.html",
controller: ['$scope', '$filter', function ($scope, $filter) {
// Your behaviour goes here :)
}]
}
@mgonto
mgonto / main.html
Created March 23, 2013 03:51
Templates angular
<div>
<div header></div>
<div class="main-content">
<p>
Here it's this page specific content :)
</p>
</div>
<div footer></div>
package drivers;
import java.io.File;
import java.sql.SQLException;
import java.util.List;
import javax.persistence.Entity;
import org.hibernate.dialect.Dialect;
import org.hibernate.ejb.Ejb3Configuration;
@mgonto
mgonto / directives.js
Created April 5, 2013 21:57
tabs example
angular.module('components', []).
directive('tabs', function() {
return {
restrict: 'E',
transclude: true,
scope: {},
controller: function($scope, $element) {
var panes = $scope.panes = [];
$scope.select = function(pane) {
@mgonto
mgonto / app.js
Created April 10, 2013 00:14
Restangular configuration
var app = angular.module('angularjs-starter', ['restangular']);
// Using RestangularProvider we can configure properties. To check all properties go to https://github.com/mgonto/restangular
app.config(function(RestangularProvider) {
RestangularProvider.setBaseUrl('/api/v1');
});
// Here it injects Restangular by itself
angular.module('angularjs-starter').controller('NewCtrl', function($scope, Restangular) {
// My controller
@mgonto
mgonto / restangular.js
Last active December 16, 2015 00:49
Restangular Usage
// First way of creating a Restangular object. Just saying the base URL
var baseAccounts = Restangular.all('accounts');
// This will query /accounts and return a promise. As Angular supports setting promises to scope variables
// as soon as we get the information from the server, it will be shown in our template :)
$scope.allAccounts = baseAccounts.getList();
var newAccount = {name: "Gonto's account"};
// POST /accounts
@mgonto
mgonto / options.js
Last active December 16, 2015 00:58
Restangular create
// Option 1
// POST /accounts/123/buildings
account.post('buildings', building)
// Option 2
// POST /accounts/
account.post(newAccount)