亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

關注新添加的輸入元素

關注新添加的輸入元素

泛舟湖上清波郎朗 2019-07-13 14:34:34
我有一個新的角2應用程序和一個列表input盒子。當用戶按下返回鍵時,我將添加一個新的input框位于當前正在編輯的框后面?;蛘哒f,我(異步地)在模型中的數組中添加了一個新條目,這將導致角2自動生成一個新的input在不久的將來。我怎樣才能做到input自動將焦點更改到新添加的元素?編輯1:或者,我得到一個模型對象的引用,該對象導致生成DOM。從組件代碼中,是否有一種方法可以搜索表示特定模型對象的DOM元素?編輯2:這是我的代碼,讓這一切順利進行。希望這是足以冒犯一些角度2的發展,以鼓勵回答:-)app.WordComponent = ng.core     .Component({         selector: 'word-editor',         template:'<input type="text" [value]="word.word" (input)="word.update($event.target.value)" (keydown)="keydown($event)"/>',         styles:[             ''         ],         properties:[             'list:list',             'word:word'         ]     })     .Class({         constructor:[             function() {             }         ],         keydown:function(e) {             if(e.which == 13) {                 var ul = e.target.parentNode.parentNode.parentNode;                 var childCount = ul.childNodes.length;                 this.list.addWord("").then(function(word) {                     var interval = setInterval(function() {                         if(childCount < ul.childNodes.length) {                             ul.lastChild.querySelector('input').focus();                             clearInterval(interval);                         }                     }, 1);                 });             }         }     });
查看完整描述

3 回答

?
BIG陽

TA貢獻1859條經驗 獲得超6個贊

這可能就是你要找的:

import?{Component,?ViewChild}?from?'angular2/core'

@Component({
??selector:?'my-app',
??providers:?[],
??template:?`
????<div>
??????<input?#name>
????</div>
??`,
??directives:?[]
})
export?class?App?{

??@ViewChild('name')?vc:?ElementRef;

??ngAfterViewInit()?{
????this.vc.nativeElement.focus();
??}
}


查看完整回答
反對 回復 2019-07-13
  • 3 回答
  • 0 關注
  • 549 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號