Advertisement
sixlsix

angular stuff

May 16th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. angular.js
  2.  
  3. *************************************
  4. directive - html tag marker that tells angular to run a reference on some javascript code
  5.  
  6. //example
  7. <html ng-app="store"> //this references store module
  8. <body ng-controller="StoreController as store" //sets the controller for html element
  9. <div ng-repeat="product in store.products" //like a foreach for specified collection and uses html element as template
  10. <div ng-hide="product.soldOut" //hides element depending on bool value specified
  11. <div ng-show="product.canPurchase" //shows element depending on bool value specified
  12. <div ng-show="tab === 1"> //can also use expressions for logic
  13. <section ng-init="tab = 1"> //initialize a value
  14. <img ng-src="{{product.images[0].full}}"/> //ng-src supplies img source AFTER expression has evaluated
  15. <a href ng-click="tab = 1"></a> //expression to evaluate
  16. <li ng-class="{active:tab === 3}"> //sets class (in this case it is class 'actice') if the expression is true
  17. ********************************
  18.  
  19. *******************************
  20. modules - pieces of Angular application that you write, can define dependencies between modules
  21.  
  22. ***********************
  23.  
  24. **********************
  25. expressions - allow you to insert dynamic values into your html
  26.  
  27. <p>
  28. {{4 + 6}}   //this will render out to display 10 on the page
  29. {{"hello" + " you"}} //this will render out to display "hello you" on the page
  30. </p>
  31. *********
  32.  
  33. *******************
  34. controllers - these atre where we define our app's behavior by defining functions and values
  35.  
  36. <div ng-controller="StoreController as store">
  37.             <h1> {{store.product.name}} </h1>
  38.             <h2> ${{store.product.price}} </h2>
  39.             <p> {{store.product.description}} </p>
  40. </div>
  41. ***************
  42.  
  43. ***************************
  44. filter - pipe data value into filter
  45.  
  46. {{data | filter:options}}
  47.  
  48. {{product.price | currency}}
  49. {{'todo item' | uppercase}}
  50. {{'description' | limitTo:8}} //limits # of characters
  51. <li ng-repeat="product in store.products | limitTo: 3"> //limits # of items shown to 3
  52. <ling-repeat="product in store.products | orderBy:'-price'"> //list prices descending because of "-" in front of price
  53. *********************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement