/** * 多行文本框 */ import template from "./Textarea.html"; import style from "antd/lib/input/style/index.css"; angular.module("esNgAntd").directive("antdTextarea", function () { return { controllerAs: "antdTextarea", restrict: "E", transclude: true, replace: true, scope: { context: "=", showCount: "@", maxLength: "@", placeholder: "@", onChange: "&", value: "@", }, template: template, controller: function ($scope, $element, $attrs) { this.getContext = function () { return $scope; }; $scope.state = { value: $scope.value, count: 0, maxLength: $scope.maxLength || "off", }; $scope.handleKeyup = function (event) { if (!$scope.event) { $scope.event = event; } if ($scope.state.maxLength === "off") { return; } let target = event.target; $scope.state.count = target.value.length; }; $scope.handleClick = function (event) { if (!$scope.event) { $scope.event = event; } }; $scope.handleChange = function () { // this.props.onChange(this.state.value, this.props.context); $scope.onChange({ event: $scope.event, }); }; }, link: function ($scope, $element, $attrs, $controllers, $transclude) { if (!document.querySelector("#ant-input")) { let styleElement = document.createElement("style"); styleElement.setAttribute("id", "ant-input"); styleElement.setAttribute("type", "text/css"); styleElement.innerHTML = style.toString(); document.head.appendChild(styleElement); } }, }; });