[英]Can I use a custom built Angular component as a placeholder for an Input field
I'm new to Angular.我是 Angular 的新手。 I'm working on a project.
我正在做一个项目。 I have created a custom
month-picker
component in Angular 6
from the scratch (*because I'm not allowed to outsource any 3rd party library not even bootstrap
, fontawesome
or primeng
) and for that I want a simple text field inside which I want to show a simple calendar icon.我从头开始在
Angular 6
创建了一个自定义month-picker
组件(* 因为我不允许外包任何 3rd 方库,甚至没有bootstrap
, fontawesome
或primeng
),为此我想要一个简单的文本字段,我想要显示一个简单的日历图标。 I tried few solutions.我尝试了几种解决方案。 This is most relevant but they are using
AngularJS
. 这是最相关的,但他们使用的是
AngularJS
。 This is also somewhat different. 这也有些不同。 This is also not very useful.
这也不是很有用。 Here is my code.
这是我的代码。 I also created a CodePen .
我还创建了一个CodePen 。
timeselector.component.html时间选择器.component.html
<our-icon class="icon-our-calendar"></our-icon>
<input class="input-field" type="text">
Note: <our-icon>
is my organisation's own library of icons.注意:
<our-icon>
是我组织自己的图标库。 I'm not allowed to go beyond that.我不被允许超越这一点。
I was trying this on CodePen but using some hex code for the icon.我在 CodePen 上尝试过这个,但对图标使用了一些十六进制代码。 Is there anyway I can add
our-icon
tag as a placeholder to the input field like this:无论如何,我可以将
our-icon
标签作为占位符添加到输入字段中,如下所示:
<input class="input-field" type="text" placeholder="<our-icon class="icon-our-calendar"></our-icon>">
I know this is completely wrong but just wanted to give you an idea what I actually mean.我知道这是完全错误的,但只是想让您了解我的实际意思。
But first I want to ask is it even doable or I'm simply wasting everyone's time.但首先我想问一下它是否可行,或者我只是在浪费每个人的时间。 Please give me some direction.
请给我一些方向。
This is just a css
problem.这只是一个
css
问题。 Treat icon and input as different elements rather than incorporating with each other.将图标和输入视为不同的元素,而不是相互结合。
Make position: absolute
for icon and apply padding according to size of icon so that input start after the icon.使
position: absolute
图标并根据图标大小应用填充,以便在图标之后开始输入。
CSS CSS
input {
width: 450px;
padding: 5px 35px;
height: 25px;
}
.input-wrapper {
position: relative;
}
.input-wrapper .input-icon {
position: absolute;
padding: 12px;
}
Template模板
<div class="input-wrapper">
<app-our-icon class="input-icon"></app-our-icon>
<input>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.