简体   繁体   English

触发angular2中元素的焦点

[英]Trigger focus in elements in angular2

I have a component as (Angular 4.1.0) - 我有一个组件为(Angular 4.1.0)-

<div id="create1" style="height: auto" materialize>
 <div class="input-field" style="height: auto">
   <textarea id="**create-post**" class="materialize-textarea"></textarea>
   <label for="create-post">Write something ...</label>
 </div>
 <div class="card-action">
  <a class="left"><i class="material-icons">**close**</i> </a>
  <a class="right">Post</a>
 </div>

1.So the problem is when I focus on [ create-post ] element then it should trigger the [ close ] element also, else the [ close ] element should be hidden. 1.所以问题是当我专注于[ create-post ]元素时,它也应该触发[ close ]元素,否则[ close ]元素应该被隐藏。

the component css has this - 组件css具有-

.input-field textarea:focus {
border-bottom: 1px solid #00b8d4;
box-shadow: 0 1px 0 0 #00b8d4;
**height**: 400px;}

2.although the height :400px but when the content increases of the textarea it should also extend its height! 2.虽然高度为 :400px,但是当文本区域的内容增加时,它的高度也应该增加! Contents should not become scrollable instead the textarea should increase its height anyone have any idea how to attain this? 内容不应变为可滚动,而文本区域应增加其高度。任何人都不知道该如何实现?

You can bind to the focus event in angular directly in your template and connect it to the javascript to do whatever you need to do. 您可以直接在模板中按角度绑定到focus事件,然后将其连接到javascript以执行所需的操作。

<textarea id="**create-post**" (focus)="doWhatsNeeded()"></textarea>

then in your component declare the function: 然后在您的组件中声明函数:

doWhatsNeeded(){
    //do something
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM