diff --git a/build/Input/Input.js b/build/Input/Input.js index b66792e..3cfa853 100644 --- a/build/Input/Input.js +++ b/build/Input/Input.js @@ -1,97 +1,81 @@ import style from "antd/lib/input/style/index.css"; -angular - .module("esNgAntd") - .directive("antdInput", function ($compile, esNgAntd) { - return { - controllerAs: "antdInput", - restrict: "E", - transclude: true, - replace: true, - scope: { - value: "@", - placeholder: "@", - addonBefore: "@", - addonAfter: "@", - disabled: "@", - onChange: "&", - maxLength: "@", - }, - controller: function ($scope, $element, $attrs) { - this.getContext = function () { - return $scope; - }; +angular.module("esNgAntd").directive("antdInput", ["$compile", "esNgAntd", function ($compile, esNgAntd) { + return { + restrict: "E", + replace: true, + transclude: true, + scope: { + value: "@", + placeholder: "@", + addonBefore: "@", + addonAfter: "@", + disabled: "=", + onChange: "&", + maxLength: "=" + }, + require: ["^?antdFormItem", "^?antdForm"], + controller: function ($scope, $element, $attrs) { + $scope.state = { + inputEventTarget: null + }; - $scope.state = { - inputEventTarget: null, - }; + $scope.handleClick = function (event) { + $scope.state.inputEventTarget = event; + }; - $scope.handleClick = function (event) { - $scope.state.inputEventTarget = event; - }; + $scope.handleChange = function () { + $scope.onChange({ + event: $scope.state.inputEventTarget + }); + }; - $scope.handleChange = function () { - $scope.onChange({ - event: $scope.state.inputEventTarget, - }); - }; + $scope.getTemplate = function () { + let maxLengthAttribute = ""; + let styleAttribute = ""; + let idAttribute = ""; - $scope.getTemplate = function () { - let maxLengthAttribute = ""; - let styleAttribute = ""; - let idAttribute = ""; + if ($scope.maxLength) { + maxLengthAttribute = `maxlength="${$scope.maxLength}"`; + } - if ($scope.maxLength) { - maxLengthAttribute = `maxlength="${$scope.maxLength}"`; - } + if ($scope.style) { + styleAttribute = `style="${$scope.style}"`; + } - if ($scope.style) { - styleAttribute = `style="${$scope.style}"`; - } + if ($scope.antdFormItem && $scope.antdFormItem.name) { + idAttribute = `id="${$scope.antdFormItem.name}"`; + } - if ($scope.antdFormItem && $scope.antdFormItem.name) { - idAttribute = `id="${$scope.antdFormItem.name}"`; - } - - let templates = [ - ``, - ` + let templates = [``, ` {{addonBefore}} - + {{addonAfter}} - `, - ]; + `]; - if ($scope.addonBefore || $scope.addonAfter) { - return templates[1]; - } else { - return templates[0]; - } - }; - }, - require: ["?^antdFormItem", "?^antdForm"], - link: function ( - $scope, - $element, - $attrs, - $controllers, - $transclude - ) { - let [antdFormItem, antdForm] = $controllers; - esNgAntd.createStyle("ant-input", style); // 上下文 + if ($scope.addonBefore || $scope.addonAfter) { + return templates[1]; + } else { + return templates[0]; + } + }; + }, + link: function ($scope, $element, $attrs, $controllers) { + let [antdForm, antdFormItem] = $controllers; + esNgAntd.createStyle("ant-input", style); // 上下文 - if (antdForm) { - $scope.antdForm = antdForm.getContext(); - $scope.antdForm.state.formItems.push($scope); - } + if (antdForm) { + $scope.antdForm = antdForm.getContext(); + $scope.antdForm.state.formItems.push($scope); + } - if (antdFormItem) { - $scope.antdFormItem = antdFormItem.getContext(); - } + if (antdFormItem) { + $scope.antdFormItem = antdFormItem.getContext(); + } - $scope.style = $attrs.style; - $element.replaceWith($compile($scope.getTemplate())($scope)); - }, - }; - }); + $scope.style = $attrs.style; + $element.replaceWith($compile($scope.getTemplate())($scope)); + } + }; +}]); \ No newline at end of file diff --git a/dist/ng-antd.js b/dist/ng-antd.js index c7c18f4..2b668a5 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\n .module(\"esNgAntd\")\n .directive(\"antdInput\", function ($compile, esNgAntd) {\n return {\n controllerAs: \"antdInput\",\n restrict: \"E\",\n transclude: true,\n replace: true,\n scope: {\n value: \"@\",\n placeholder: \"@\",\n addonBefore: \"@\",\n addonAfter: \"@\",\n disabled: \"@\",\n onChange: \"&\",\n maxLength: \"@\",\n },\n controller: function ($scope, $element, $attrs) {\n this.getContext = function () {\n return $scope;\n };\n\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 `\n \n {{addonBefore}}\n \n {{addonAfter}}\n \n `,\n ];\n\n if ($scope.addonBefore || $scope.addonAfter) {\n return templates[1];\n } else {\n return templates[0];\n }\n };\n },\n require: [\"?^antdFormItem\", \"?^antdForm\"],\n link: function (\n $scope,\n $element,\n $attrs,\n $controllers,\n $transclude\n ) {\n let [antdFormItem, antdForm] = $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\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 (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?"); /***/ }), diff --git a/example/input.html b/example/input.html index d122b02..6a4ace5 100644 --- a/example/input.html +++ b/example/input.html @@ -16,32 +16,32 @@