Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AngularDart Introduction

AngularDart Introduction

Since recently AngularJS has a new sibling called AngularDart. Both are based on the same concepts.

With AngularDart you can write web applications using Angular concepts and leveraging the benefits of the Dart language.

Nikolaus Graf

April 17, 2014
Tweet

More Decks by Nikolaus Graf

Other Decks in Programming

Transcript

  1. “ ” #dartlang Brad Green Our goal is that there

    will be a single framework with your choice of language.
  2. #dartlang Extend HTML <div  ng-­‐click=“ctrl.doSomething()”>Click  Me</div>   ! ! !

    <my-­‐calendar  select-­‐date=“2014-­‐02-­‐12”></my-­‐calendar>
  3. #dartlang Dependency Injection //  hard  coded  dependency   class  SomeClass()

     {          this.myObject  =  new  MyClass();   }   ! //  dependency  injection   class  SomeClass  (MyClass  myObject)  {          this.myObject  =  myObject;   }
  4. #dartlang <!DOCTYPE  html>   <html  ng-­‐app>   <head></head>   <body>

         <script  src=“packages/shadow_dom/shadow_dom.min.js">      </script>      <script  type="application/dart"  src="main.dart">      </script>      <script  type="text/javascript"  src=“packages/browser/ dart.js">      </script>   </body>   </html> index.html
  5. #dartlang <!DOCTYPE  html>   <html  ng-­‐app>   <head></head>   <body>

      !    <h3>Hello  {{name}}!</h3>      Name:  <input  type="text"  ng-­‐model="name">   !    <script  src=“packages/shadow_dom/shadow_dom.min.js">      </script>      <script  type="application/dart"  src="main.dart"></ script>      <script  type="text/javascript"  src=“packages/browser/ dart.js">      </script>   </body>   </html> index.html
  6. #dartlang <div  recipe-­‐book>      <ul>        

     <li  ng-­‐repeat="recipe  in  ctrl.recipes">              {{recipe.name}}          </li>      </ul>   </div> index.html
  7. #dartlang class  RecipeBookController  {   !    List<Recipe>  recipes;  

    !    RecipeBookController()  {          recipes  =  _loadData();      }   !    List<Recipe>  _loadData()  {          return  [  new  Recipe('My  Appetizer',                      ["Ingredient  1",  "Ingredient  2"])  ];      }   } recipe_book.dart
  8. #dartlang @NgController(          selector:  '[recipe-­‐book]',    

         publishAs:  'ctrl')   class  RecipeBookController  {      … recipe_book.dart
  9. #dartlang class  MyAppModule  extends  Module  {      MyAppModule()  {

             type(RecipeBookController);      }   }   ! main()  {      ngBootstrap(module:  new  MyAppModule());   } main.dart
  10. “ ” #dartlang Eric Bidelman Shadow DOM gives us markup

    encapsulation, style boundaries, and exposes (to web developers) the same mechanics browsers vendors have been using to implement their internal UI. Shadow DOM
  11. #dartlang class  RatingComponent  {   !    @NgTwoWay('rating')    

     int  rating;   !    void  handleClick(int  value)  {          rating  =  value;      }   !    String  renderCharacter(int  index)  {          return  index  >  rating  ?  "0"  :  "X";      }   } rating_component.dart
  12. #dartlang @NgComponent(          selector:  'rating',    

         templateUrl:  'rating_component.html',          cssUrl:  'rating_component.css',          publishAs:  'cmp'   )   class  RatingComponent  {        … rating_component.dart
  13. #dartlang class  MyAppModule  extends  Module  {   !    MyAppModule()

     {          type(RecipeBookController);          type(RatingComponent);      }   }   ! main()  {      ngBootstrap(module:  new  MyAppModule());   }   main.dart
  14. #dartlang @NgController ! Application-specific logic Example: recipe-book ! @NgComponent !

    Custom elements Example: rating ! @NgDirective ! Decorator that adds logic to existing elements Examples: tooltip, ng-class
  15. #dartlang @NgFilter(name:  'categoryfilter')   class  CategoryFilter  {      call(recipeList,

     filterMap)  {          if  (recipeList  is  List  &&  filterMap  is  Map)  {              //  filter  for  something  here              return  recipeList.toList();          }      }   } category_filter.dart
  16. Services #dartlang ! Services are substitutable objects that are wired

    together using dependency injection. You can use services to organize and share code across your app. ! ! Angular for example provides a built-in service called the Http Service that handles making HTTP requests to the server. ! !