Skip to content

Instantly share code, notes, and snippets.

View jbmilgrom's full-sized avatar

Jonathan Milgrom jbmilgrom

View GitHub Profile
$scope = null; // $scope object will be garbage collected, but nothing else
$scope.$parent = $scope.$$nextSibling = $scope.$$prevSibling = $scope.$$childHead =
 $scope.$$childTail = $scope.$root = $scope.$$watchers = null;
angular.module('myModule').controller('fileUploadCtrl', function($scope, FileUploader){
$scope.uploader = new FileUploader({
settings: {}
});
var reader = new FileReader();
reader.onload = function(event) {
var img = new Image();
scope.tree = {
type: 'oak',
branches: [{
color: 'brown',
length: '11',
leaves: [{
color: 'green',
shape: 'oval',
}, {
color: 'brown',
scope.greeting = 'hi there';
scope.$watch('greeting', function(greeting) {
console.log('greeting: ', greeting); // greeting: hi there
});
var fullName = 'last + ", " + first';
var getFullName = $parse(fullName); // getFullName is the parseFn!
var context = {first: 'steph', last: 'curry'};
getFullName(context); // => curry, steph
context = {first: 'russ', last: 'westbrook'};
getFullName(context); // => westbrook, russ
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.firstTeam = [{
first: 'steph',
last: 'curry'
}, {
first: 'lebron',
last: 'james'
}];
$scope.$watchCollection('firstTeam', function(firstTeamArray) {
console.log("change to the first team! ", JSON.stringify(firstTeamArray));
});
var context = {first: 'steph', last: 'curry'};
// with string
var string = 'last + ", " + first';
var parseFn = $parse(string);
parseFn(context); // => curry, steph
// with function
var func = function(context) {
return context.last + ', ' + context.first;
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'}
});