This repository was archived by the owner on Apr 12, 2024. It is now read-only.
  
  
  - 
                Notifications
    
You must be signed in to change notification settings  - Fork 27.3k
 
FAQ
        ProLoser edited this page Mar 19, 2013 
        ·
        39 revisions
      
    You made the right choice citizen. Read everything you can find, starting with this list:
- DO NOT perform DOM selection/traversal from the controller. The HTML hasn't rendered yet. Look up 'directives'
 - Calling 
angular.module('myApp', [])will ALWAYS create a new module (and wipe out your existing one). Make sure to doangular.module('myApp')with only 1 parameter to refer to an already created module. - You will probably want ng-bind-html-unsafe sooner or later
 - 
$scope.$watchhas a third parameter to monitor changes by value (and not by reference) - Don't try to serialize the form or collect the input values manually. Just slap 
ng-model="data.myField"onto every form input you use and then take a gander at$scope.datawhen you finally need it.- Always have a '.' in your ng-models. Misko best practice.
 
 - $rootScope is essentially where you put ng-app. You can inject $rootScope into your bootstrap or services to add stuff that's accessible on all scopes.
 - The difference between 
module().factory()andmodule().service() - Prevent Flash Of Unstyled Content (FOUC) (and curly braces) by mixing 
ng-bindwithng-cloak - Nested Routes / Views? Maybe...
 - You can always do 
<script id="some/partial.html" type="text/ng-template">and angular will use it instead! - Escape the port in 
$resource('example.com\\:8080') - Angular watches the input event, not the 'change' event
 - Don't use jQuery to toggle crap. Just use a lot of variable flags inline: 
<a ng-click="flags.open=!flags.open">...<div ng-class="{active:flags.open}"> - If you're on Google Chrome install the Batarang extension, inspect a DOM element, and type 
$scopein the console - Checkout AngularUI for an awesome collection of directives (and even BETTER example code)
 - For IE v8.0 or earlier you may want to read this and use this
 - If you want to get rid of the 
#in your routes, search the docs forhtml5mode - You should try using the AngularUI Passthru Directive (uiJq) before trying to roll your own
 - Learn Javascript
 - Get the AngularJS CheatSheet
 - If you change 
newValinside your$scope.$watchit could fire again (recursively?) - You should ONLY use 
$scope.$applyin non-angular events/callbacks. It usually doesn't belong anywhere else. 
