Advertisement
Guest User

pipiripi

a guest
Mar 26th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en" ng-app="app">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. <script src="angular.min.js"></script>
  7.  
  8. <style>
  9. html{
  10. font-size: 1em;
  11. font-family: Verdana;
  12. }
  13. .cmp{
  14. background-color: red;
  15. }
  16. </style>
  17. </head>
  18. <body ng-controller="micontrolador as ctrl">
  19.  
  20. <key-value-combo title="Size" selecteditem="ctrl.selectedsize" items="ctrl.sizeelements" ></key-value-combo>
  21. {{ctrl.selectedsize}}
  22.  
  23. <key-value-combo title="ProductType" selecteditem="ctrl.selectedproducttype" items="ctrl.producttypeelements" ></key-value-combo>
  24. {{ctrl.selectedproducttype}}
  25.  
  26.  
  27.  
  28. <script>
  29.  
  30. var app = angular.module("app", []);
  31.  
  32. app.controller("micontrolador", function(){
  33.  
  34. this.sizeelements = [{id: 1, caption: "50 LITROS"},{id: 2, caption: "100 LITROS"}];
  35. this.selectedsize = 1;
  36.  
  37. this.producttypeelements = [{id: 1, caption: "BEER"},{id: 2, caption: "CIDER"}];
  38. this.selectedproducttype = 1;
  39.  
  40.  
  41.  
  42.  
  43.  
  44. });
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51. app.component('keyValueCombo', {
  52. restrict:'E',
  53. template:
  54. '<div> ' +
  55. ' <h1>{{ctrl.title}}</h1> ' +
  56. ' <select ' +
  57. ' ng-model = "ctrl.selecteditem" ' +
  58. ' ng-options = "item.id as item.caption for item in ctrl.items" ' +
  59. ' ng-change = "ctrl.update(ctrl.selecteditem)"> ' +
  60. ' </select> ' +
  61. '</div>',
  62.  
  63. controllerAs:'ctrl',
  64. bindings: {
  65. title: '@',
  66. items: '<',
  67. selecteditem: "="
  68. },
  69. controller: function(){
  70. var vm = this;
  71. vm.update = function(e) {
  72. console.log("ahora");
  73.  
  74. }
  75.  
  76.  
  77.  
  78.  
  79.  
  80. }
  81. });
  82. </script>
  83.  
  84. </body>
  85. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement