This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// bad | |
if (currentUser) { | |
function test() { | |
console.log('Nope.'); | |
} | |
} | |
// good | |
if (currentUser) { | |
var test = function test() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'}). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 :) | |
}] | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 :) | |
}] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
<div header></div> | |
<div class="main-content"> | |
<p> | |
Here it's this page specific content :) | |
</p> | |
</div> | |
<div footer></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('components', []). | |
directive('tabs', function() { | |
return { | |
restrict: 'E', | |
transclude: true, | |
scope: {}, | |
controller: function($scope, $element) { | |
var panes = $scope.panes = []; | |
$scope.select = function(pane) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Option 1 | |
// POST /accounts/123/buildings | |
account.post('buildings', building) | |
// Option 2 | |
// POST /accounts/ | |
account.post(newAccount) |