第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

關(guān)注新添加的輸入元素

關(guān)注新添加的輸入元素

泛舟湖上清波郎朗 2019-07-13 14:34:34
我有一個新的角2應(yīng)用程序和一個列表input盒子。當(dāng)用戶按下返回鍵時,我將添加一個新的input框位于當(dāng)前正在編輯的框后面。或者說,我(異步地)在模型中的數(shù)組中添加了一個新條目,這將導(dǎo)致角2自動生成一個新的input在不久的將來。我怎樣才能做到input自動將焦點更改到新添加的元素?編輯1:或者,我得到一個模型對象的引用,該對象導(dǎo)致生成DOM。從組件代碼中,是否有一種方法可以搜索表示特定模型對象的DOM元素?編輯2:這是我的代碼,讓這一切順利進行。希望這是足以冒犯一些角度2的發(fā)展,以鼓勵回答:-)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條經(jīng)驗 獲得超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();
??}
}


查看完整回答
反對 回復(fù) 2019-07-13
  • 3 回答
  • 0 關(guān)注
  • 548 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號