option.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { Directive, ElementRef, EventEmitter, Input, Output } from '@angular/core';
  2. import { isPresent, isTrueProperty } from '../../util/util';
  3. /**
  4. * @name Option
  5. * @description
  6. * `ion-option` is a child component of `ion-select`. Similar to the native option element, `ion-option` can take a value and a selected property.
  7. *
  8. * @demo /docs/demos/src/select/
  9. */
  10. var Option = (function () {
  11. function Option(_elementRef) {
  12. this._elementRef = _elementRef;
  13. this._selected = false;
  14. this._disabled = false;
  15. /**
  16. * @output {any} Event to evaluate when option is selected.
  17. */
  18. this.ionSelect = new EventEmitter();
  19. }
  20. Object.defineProperty(Option.prototype, "disabled", {
  21. /**
  22. * @input {boolean} If true, the user cannot interact with this element.
  23. */
  24. get: function () {
  25. return this._disabled;
  26. },
  27. set: function (val) {
  28. this._disabled = isTrueProperty(val);
  29. },
  30. enumerable: true,
  31. configurable: true
  32. });
  33. Object.defineProperty(Option.prototype, "selected", {
  34. /**
  35. * @input {boolean} If true, the element is selected.
  36. */
  37. get: function () {
  38. return this._selected;
  39. },
  40. set: function (val) {
  41. this._selected = isTrueProperty(val);
  42. },
  43. enumerable: true,
  44. configurable: true
  45. });
  46. Object.defineProperty(Option.prototype, "value", {
  47. /**
  48. * @input {any} The value of the option.
  49. */
  50. get: function () {
  51. if (isPresent(this._value)) {
  52. return this._value;
  53. }
  54. return this.text;
  55. },
  56. set: function (val) {
  57. this._value = val;
  58. },
  59. enumerable: true,
  60. configurable: true
  61. });
  62. Object.defineProperty(Option.prototype, "text", {
  63. /**
  64. * @hidden
  65. */
  66. get: function () {
  67. return this._elementRef.nativeElement.textContent;
  68. },
  69. enumerable: true,
  70. configurable: true
  71. });
  72. Option.decorators = [
  73. { type: Directive, args: [{
  74. selector: 'ion-option'
  75. },] },
  76. ];
  77. /** @nocollapse */
  78. Option.ctorParameters = function () { return [
  79. { type: ElementRef, },
  80. ]; };
  81. Option.propDecorators = {
  82. 'disabled': [{ type: Input },],
  83. 'selected': [{ type: Input },],
  84. 'value': [{ type: Input },],
  85. 'ionSelect': [{ type: Output },],
  86. };
  87. return Option;
  88. }());
  89. export { Option };
  90. //# sourceMappingURL=option.js.map