Skip to content

Instantly share code, notes, and snippets.

View jbmilgrom's full-sized avatar

Jonathan Milgrom jbmilgrom

View GitHub Profile
<input type="text" ng-model="modelName" nullify-model>
.directive('nullifyModel', ['$filter',
function($filter){
return {
restrict: 'A',
require: "ngModel",
link: link
};
function link(scope, elem, attrs, ctrl){
ctrl.$parsers.push($filter('nullify'));
.filter('nullify', function(){
return function(value){
return value ? value : null;
};
});
<i class="icon upvote" ng-click="vm.user.upvote(vm.answer)"></i>
<i class="icon upvote"
ng-click="vm.user.upvote(vm.answer)"
ng-class="{voted: vm.answer.isVotedFor(vm.user)}">
</i>
<i class="icon upvote"
ng-click="vm.user.upvote(vm.answer)"
ng-class="{voted: vm.answer.isVotedFor(vm.user)}">
</i>
{{ vm.answer.voteCount() }}
<i class="icon downvote"
ng-click="vm.user.downvote(vm.answer)"
ng-class="{voted: vm.answer.isVotedAgainst(vm.user)}">
</i>
scope.$watch('greeting', function(greeting) {
console.log('greeting: ', greeting);
});
scope.greeting = 'hi there'; // greeting: hi there
$timeout(function() { scope.greeting += ', Joe'}); // greeting: hi there, Joe
scope.tree = {
type: 'oak',
branches: [{
color: 'brown',
length: '11',
leaves: [{
color: 'green',
shape: 'oval',
}, {
color: 'brown',
scope.$watch('obj1', function callback(newValue) {
console.log('obj1: ', newValue);
});
// (when initialized) prints out: undefined
$timeout(function() {
scope.obj1 = {name: 'jonathan'}; // prints out: {name: 'jonathan'}
});
scope.$watchGroup(['expression1', 'expression2'], function(arrayOfExpressions) {
...
});