{"id":156,"date":"2017-10-25T23:38:43","date_gmt":"2017-10-25T23:38:43","guid":{"rendered":"http:\/\/dart.honobono-life.info\/?p=156"},"modified":"2017-10-25T23:38:43","modified_gmt":"2017-10-25T23:38:43","slug":"angulardart-v4-custom-pipe-orderbypipe","status":"publish","type":"post","link":"http:\/\/dart.honobono-life.info\/?p=156","title":{"rendered":"AngularDart v4 Custom pipe, OrderByPipe"},"content":{"rendered":"AngularDart v4 Sample Code,Demo<br \/>\r\n<!--more-->\r\n<ul>\r\n<li>AngularDart : 4.0.0<\/li>\r\n<li>Dart : 1.24.1<\/li>\r\n<\/ul>\r\n<div role=\"tabpanel\">\r\n  <ul class=\"nav nav-tabs\">\r\n    <li class=\"active\"><a href=\"#demo1\" data-toggle=\"tab\">demo<\/a><\/li>\r\n    <li><a href=\"#html1\" data-toggle=\"tab\">markup<\/a><\/li>\r\n    <li><a href=\"#script1\" data-toggle=\"tab\">dart<\/a><\/li>\r\n  <\/ul>\r\n  <div class=\"tab-content\">\r\n    <div class=\"tab-pane active\" id=\"demo1\">\r\n\r\n<my-app>Loading&#8230;<\/my-app>\r\n\r\n    <\/div>\r\n    <div class=\"tab-pane\" id=\"html1\">\r\n\r\n<pre>\r\n(html)\r\n&lt;head>\r\n.....\r\n  &lt;script defer src=\"main.dart\" type=\"application\/dart\">&lt;\/script>\r\n  &lt;script defer src=\"packages\/browser\/dart.js\">&lt;\/script>\r\n&lt;\/head>\r\n&lt;body>\r\n  &lt;my-app>Loading...&lt;\/my-app>\r\n&lt;\/body>\r\n\r\n(pubspec.yaml)\r\n.....\r\nenvironment:\r\n  sdk: '>=1.24.0 <2.0.0'\r\ndependencies:\r\n  angular: ^4.0.0\r\n  angular_forms: ^1.0.0\r\n  angular_router: ^1.0.2\r\n  http: ^0.11.0\r\n  stream_transform: ^0.0.6\r\n\r\ndev_dependencies:\r\n  angular_test: ^1.0.0\r\n  browser: ^0.10.0\r\n  dart_to_js_script_rewriter: ^1.0.1\r\n  mockito: ^2.0.2\r\n  test: ^0.12.21\r\n\r\ntransformers:\r\n- angular:\r\n    entry_points:\r\n    - web\/main.dart\r\n    - test\/**_test.dart\r\n- test\/pub_serve:\r\n    $include: test\/**_test.dart\r\n- dart_to_js_script_rewriter\r\n<\/pre>\r\n    <\/div>\r\n\r\n    <div class=\"tab-pane\" id=\"script1\">\r\n<pre>\r\n(main.dart)\r\nimport 'package:angular\/angular.dart';\r\nimport 'orderby_pipe.dart';\r\n\r\n@Component(\r\n  selector: 'my-app',\r\n  template: '''\r\n&lt;table class=\"table\">\r\n  &lt;thead>\r\n    &lt;tr>&lt;th>Product Name&lt;\/th>&lt;th>Product Price&lt;\/th>&lt;\/tr>\r\n  &lt;\/thead>\r\n  &lt;tbody>\r\n    &lt;tr *ngFor=\"let item of products | orderby: key\">\r\n      &lt;td>{{item[\"name\"]}}&lt;\/td>\r\n      &lt;td>{{item[\"price\"] | currency:'JPY':true}}&lt;\/td>\r\n    &lt;\/tr>\r\n  &lt;\/tbody>\r\n&lt;\/table>\r\n    ''',\r\n  directives: const [CORE_DIRECTIVES],\r\n  pipes: const [COMMON_PIPES, OrderbyPipe]\r\n)\r\nclass AppComponent {\r\n  List&lt;Map> products = [\r\n    { \"name\": \"digital camera-A\",\"price\": 8500},\r\n    { \"name\": \"digital camera-D\",\"price\": 3500},\r\n    { \"name\": \"computer-B\"      ,\"price\": 15900},\r\n    { \"name\": \"digital camera-B\",\"price\": 9800},\r\n    { \"name\": \"computer-D\"      ,\"price\": 5900},\r\n    { \"name\": \"computer-C\"      ,\"price\": 25900},\r\n    { \"name\": \"computer-A\"      ,\"price\": 14900}\r\n  ];\r\n  String key = 'price';\r\n}\r\n\r\nvoid main() {\r\n  bootstrap(AppComponent);\r\n}\r\n\r\n\r\n(orderby_pipe.dart)\r\nimport 'package:angular\/angular.dart';\r\n\r\n@Pipe('orderby')\r\nclass OrderbyPipe extends PipeTransform {\r\n  List&lt;Map> transform(List&lt;Map> array, String key) {\r\n    array.sort((Map a, Map b) {\r\n      if (a[key] &lt; b[key]) {\r\n        return -1;\r\n      } else if (a[key] > b[key]) {\r\n        return 1;\r\n      } else {\r\n        return 0;\r\n      }\r\n    });\r\n    return array;\r\n  }\r\n}\r\n<\/pre>\r\n    <\/div>\r\n  <\/div>\r\n<\/div>\r\n<script type=\"text\/javascript\"  src='http:\/\/dart.honobono-life.info\/wp-content\/themes\/ang\/ngdart4\/orderby.dart.js'><\/script>","protected":false},"excerpt":{"rendered":"<p>AngularDart v4 Sample Code,Demo<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"amp_enabled":true,"_links":{"self":[{"href":"http:\/\/dart.honobono-life.info\/index.php?rest_route=\/wp\/v2\/posts\/156"}],"collection":[{"href":"http:\/\/dart.honobono-life.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/dart.honobono-life.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/dart.honobono-life.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/dart.honobono-life.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=156"}],"version-history":[{"count":1,"href":"http:\/\/dart.honobono-life.info\/index.php?rest_route=\/wp\/v2\/posts\/156\/revisions"}],"predecessor-version":[{"id":157,"href":"http:\/\/dart.honobono-life.info\/index.php?rest_route=\/wp\/v2\/posts\/156\/revisions\/157"}],"wp:attachment":[{"href":"http:\/\/dart.honobono-life.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/dart.honobono-life.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=156"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/dart.honobono-life.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}