Skip to content

Instantly share code, notes, and snippets.

@Tuizi
Last active October 2, 2015 19:59
Show Gist options
  • Save Tuizi/0d4e532bbab4d145a764 to your computer and use it in GitHub Desktop.
Save Tuizi/0d4e532bbab4d145a764 to your computer and use it in GitHub Desktop.
Code tips

#Angular

Binding

"@" ( Text binding / one-way binding )

"=" ( Direct model binding / two-way binding )

"&" ( Behaviour binding / Method binding )

"?" = optionnal (no inheritance from parent scope)

$$phase

Don't do if (!$scope.$$phase) $scope.$apply(), it means your $scope.$apply() isn't high enough in the call stack.

$digest vs $apply

Usually, you don't call $digest() directly in controllers or in directives. Instead, you should call $apply() (typically from within a directive), which will force a $digest().

$evalAsync vs $timeout

  • if code is queued using $evalAsync from a directive, it should run after the DOM has been manipulated by Angular, but before the browser renders

  • if code is queued using $evalAsync from a controller, it should run before the DOM has been manipulated by Angular (and before the browser renders) -- rarely do you want this

  • if code is queued using $timeout, it should run after the DOM has been manipulated by Angular, and after the browser renders (which may cause flicker in some cases)

//Get jQuery events binded to a node
jQuery._data( element, "events" );
//Breakpoint in code when object changed
myObj = {a: 1, b: 2};
Object.observe(myObj, function (changes){
console.log("Changes:", changes);
debugger;
})
myObj.a = 42;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment