From e154891a864519d8548f59af356158ec16f9d14e Mon Sep 17 00:00:00 2001 From: Imshann <851188611@qq.com> Date: Thu, 24 Feb 2022 15:06:31 +0800 Subject: [PATCH] 优化Input组件 --- build/Input/Input.js | 11 ++++++----- dist/ng-antd.js | 2 +- src/Input/Input.js | 6 +++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/build/Input/Input.js b/build/Input/Input.js index 3cfa853..cf9b6d5 100644 --- a/build/Input/Input.js +++ b/build/Input/Input.js @@ -63,17 +63,18 @@ angular.module("esNgAntd").directive("antdInput", ["$compile", "esNgAntd", funct }, link: function ($scope, $element, $attrs, $controllers) { let [antdForm, antdFormItem] = $controllers; - esNgAntd.createStyle("ant-input", style); // 上下文 + esNgAntd.createStyle("ant-input", style); + + if (antdFormItem) { + $scope.antdFormItem = antdFormItem.getContext(); + } // 上下文 + if (antdForm) { $scope.antdForm = antdForm.getContext(); $scope.antdForm.state.formItems.push($scope); } - if (antdFormItem) { - $scope.antdFormItem = antdFormItem.getContext(); - } - $scope.style = $attrs.style; $element.replaceWith($compile($scope.getTemplate())($scope)); } diff --git a/dist/ng-antd.js b/dist/ng-antd.js index ec6d81b..7c7adce 100644 --- a/dist/ng-antd.js +++ b/dist/ng-antd.js @@ -192,7 +192,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _Ima /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var antd_lib_input_style_index_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! antd/lib/input/style/index.css */ \"./node_modules/antd/lib/input/style/index.css\");\n\nangular.module(\"esNgAntd\").directive(\"antdInput\", [\"$compile\", \"esNgAntd\", function ($compile, esNgAntd) {\n return {\n restrict: \"E\",\n replace: true,\n transclude: true,\n scope: {\n value: \"@\",\n placeholder: \"@\",\n addonBefore: \"@\",\n addonAfter: \"@\",\n disabled: \"=\",\n onChange: \"&\",\n maxLength: \"=\"\n },\n require: [\"^?antdFormItem\", \"^?antdForm\"],\n controller: function ($scope, $element, $attrs) {\n $scope.state = {\n inputEventTarget: null\n };\n\n $scope.handleClick = function (event) {\n $scope.state.inputEventTarget = event;\n };\n\n $scope.handleChange = function () {\n $scope.onChange({\n event: $scope.state.inputEventTarget\n });\n };\n\n $scope.getTemplate = function () {\n let maxLengthAttribute = \"\";\n let styleAttribute = \"\";\n let idAttribute = \"\";\n\n if ($scope.maxLength) {\n maxLengthAttribute = `maxlength=\"${$scope.maxLength}\"`;\n }\n\n if ($scope.style) {\n styleAttribute = `style=\"${$scope.style}\"`;\n }\n\n if ($scope.antdFormItem && $scope.antdFormItem.name) {\n idAttribute = `id=\"${$scope.antdFormItem.name}\"`;\n }\n\n let templates = [``, `\n \n {{addonBefore}}\n \n {{addonAfter}}\n \n `];\n\n if ($scope.addonBefore || $scope.addonAfter) {\n return templates[1];\n } else {\n return templates[0];\n }\n };\n },\n link: function ($scope, $element, $attrs, $controllers) {\n let [antdForm, antdFormItem] = $controllers;\n esNgAntd.createStyle(\"ant-input\", antd_lib_input_style_index_css__WEBPACK_IMPORTED_MODULE_0__[\"default\"]); // 上下文\n\n if (antdForm) {\n $scope.antdForm = antdForm.getContext();\n $scope.antdForm.state.formItems.push($scope);\n }\n\n if (antdFormItem) {\n $scope.antdFormItem = antdFormItem.getContext();\n }\n\n $scope.style = $attrs.style;\n $element.replaceWith($compile($scope.getTemplate())($scope));\n }\n };\n}]);\n\n//# sourceURL=webpack://ng-antd/./build/Input/Input.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var antd_lib_input_style_index_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! antd/lib/input/style/index.css */ \"./node_modules/antd/lib/input/style/index.css\");\n\nangular.module(\"esNgAntd\").directive(\"antdInput\", [\"$compile\", \"esNgAntd\", function ($compile, esNgAntd) {\n return {\n restrict: \"E\",\n replace: true,\n transclude: true,\n scope: {\n value: \"@\",\n placeholder: \"@\",\n addonBefore: \"@\",\n addonAfter: \"@\",\n disabled: \"=\",\n onChange: \"&\",\n maxLength: \"=\"\n },\n require: [\"^?antdFormItem\", \"^?antdForm\"],\n controller: function ($scope, $element, $attrs) {\n $scope.state = {\n inputEventTarget: null\n };\n\n $scope.handleClick = function (event) {\n $scope.state.inputEventTarget = event;\n };\n\n $scope.handleChange = function () {\n $scope.onChange({\n event: $scope.state.inputEventTarget\n });\n };\n\n $scope.getTemplate = function () {\n let maxLengthAttribute = \"\";\n let styleAttribute = \"\";\n let idAttribute = \"\";\n\n if ($scope.maxLength) {\n maxLengthAttribute = `maxlength=\"${$scope.maxLength}\"`;\n }\n\n if ($scope.style) {\n styleAttribute = `style=\"${$scope.style}\"`;\n }\n\n if ($scope.antdFormItem && $scope.antdFormItem.name) {\n idAttribute = `id=\"${$scope.antdFormItem.name}\"`;\n }\n\n let templates = [``, `\n \n {{addonBefore}}\n \n {{addonAfter}}\n \n `];\n\n if ($scope.addonBefore || $scope.addonAfter) {\n return templates[1];\n } else {\n return templates[0];\n }\n };\n },\n link: function ($scope, $element, $attrs, $controllers) {\n let [antdForm, antdFormItem] = $controllers;\n esNgAntd.createStyle(\"ant-input\", antd_lib_input_style_index_css__WEBPACK_IMPORTED_MODULE_0__[\"default\"]);\n\n if (antdFormItem) {\n $scope.antdFormItem = antdFormItem.getContext();\n } // 上下文\n\n\n if (antdForm) {\n $scope.antdForm = antdForm.getContext();\n $scope.antdForm.state.formItems.push($scope);\n }\n\n $scope.style = $attrs.style;\n $element.replaceWith($compile($scope.getTemplate())($scope));\n }\n };\n}]);\n\n//# sourceURL=webpack://ng-antd/./build/Input/Input.js?"); /***/ }), diff --git a/src/Input/Input.js b/src/Input/Input.js index fadaba2..e236d53 100644 --- a/src/Input/Input.js +++ b/src/Input/Input.js @@ -15,14 +15,14 @@ class Input { esNgAntd.createStyle("ant-input", style); + if (antdFormItem) { + this.antdFormItem = antdFormItem.getContext(); + } // 上下文 if (antdForm) { this.antdForm = antdForm.getContext(); this.antdForm.state.formItems.push($scope); } - if (antdFormItem) { - this.antdFormItem = antdFormItem.getContext(); - } this.props.style = $attrs.style; $element.replaceWith($compile(this.getTemplate())($scope)); } -- libgit2 0.21.2