Skip to content

Instantly share code, notes, and snippets.

View vojtajina's full-sized avatar

Vojta Jina vojtajina

View GitHub Profile
@vojtajina
vojtajina / gist:663471
Created November 5, 2010 00:47
Angular - dynamic updating select
<!DOCTYPE HTML >
<html xmlns:ng="http://angularjs.org">
<head>
<script type="text/javascript" src="http://angularjs.org/ng/js/angular-debug.js" ng:autobind></script>
<script type="text/javascript">
function testController() {
// init the value
this.options = {1: 'one', 2: 'two'};
this.change = function() {
@vojtajina
vojtajina / gist:702566
Created November 16, 2010 21:40
Angular - service example
describe('service-example', function() {
angular.service('notify', function(win) {
var msgs = [];
return function(msg) {
msgs.push(msg);
if (msgs.length == 3) {
win.alert(msgs.join("\n"));
msgs = [];
}
@vojtajina
vojtajina / angular-controller-repeater-issue.js
Created April 7, 2011 14:51
Angular issue: There is a different this (inside the method - different scope object), if controller method is defined in instance than if defined in prototype. This applies only when related element has been created by ng:repeater.
// controller
function MyCtrl() {
this.instMethod = function() {
return this.$id;
};
}
MyCtrl.prototype.protoMethod = function(index) {
return this.$id;
};
@vojtajina
vojtajina / angular-jqlite-issue-369.html
Created June 6, 2011 13:20
Angular jgLite issue #369
<!doctype html>
<html xmlns:ng="http://angularjs.org">
<head>
<script src="http://code.angularjs.org/0.9.14/angular-0.9.14.js"></script>
</head>
<body>
<script>
// create element by jqLite
var s1 = angular.element('<script>')
.attr({type: 'text/javascript', src: 'http://code.angularjs.org/0.9.15/angular-0.9.15.js?param1'});
@vojtajina
vojtajina / angular-simple-widget.html
Created June 8, 2011 15:50
Angular Simple Widget with descend(true)
<!DOCTYPE HTML>
<html xmlns:ng="http://angularjs.org">
<script type="text/javascript" src="http://code.angularjs.org/0.9.16/angular-0.9.16.min.js" ng:autobind></script>
<script type="text/javascript">
angular.widget('my:test', function(element) {
// compile children elements ?
this.descend(true);
element.append('<button type="button" ng:click="testIt()">TEST</button>');
});
@vojtajina
vojtajina / angular-cancel-route-change.html
Created July 1, 2011 15:07
Angular - cancelling $route change
<!doctype html>
<html xmlns:ng="http://angularjs.org">
<script src="http://code.angularjs.org/0.9.17/angular-0.9.17.js" ng:autobind></script>
<body>
<script>
function BookCntl() {
this.name = "BookCntl";
}
@vojtajina
vojtajina / angular-two-locations.html
Created July 20, 2011 20:31
Angular - two different $locations on single page
<!DOCTYPE html>
<html xmlns:ng="http://angularjs.org">
<head>
<title>NG playground</title>
<script src="/build/angular.js"></script>
<style>
div {margin: 5px; padding: 0 10px 10px 10px; border: 1px solid black;}
input {width: 400px;}
</style>
</head>
@vojtajina
vojtajina / angular-eventBus.js
Created July 30, 2011 13:41
Angular $eventBus
// pseudocode
angular.service('$eventBus', function() {
var listeners = {};
var mainBus = function(scope) {
return new ChildBus(mainBus, scope);
};
mainBus.emit = function(type) {
var args = Array.prototype.slice.call(arguments, 1);
@vojtajina
vojtajina / git-edit.sh
Created November 5, 2011 08:21
Simple git script for rewriting history
#!/bin/sh
#
# Simple script for rewriting history :-D
# Might be helpful when using "rebasing" strategy to keep your history nice and flat...
#
# Instalation
# >> sudo bash -c "curl https://raw.github.com/gist/1341268/git-edit.sh > /usr/local/bin/git-edit"
# >> sudo chmod a+x /usr/local/bin/git-edit
#
# Usage
@vojtajina
vojtajina / angular-ctrl-export-proposal.js
Created December 13, 2011 04:50
Angular: Export Ctrl Methods Proposal
// GOOGLE3 usage - bigger projects
var MyController = function($scope, $location) {
// controller's private state
this.$location = $location;
this.some = 12;
this.$scope = $scope;
// methods accessible from template
// these methods (defined in constructor) should contain only few logic,