我有一个有p元素的组件.它的onClick事件会将其更改为a,textarea以便用户可以编辑数据.我的问题是:
我曾尝试使用"ElementRef"和"@ViewChild()",但似乎我遗漏了一些东西:
// ------ THE CLASS
@ViewChild('tasknoteId') taskNoteRef:ElementRef;
noteEditMode: boolean = false;
get isShowNote (){
return !this.noteEditMode && this.todo.note ? true : false;
}
taskNote: string;
toggleNoteEditMode () {
this.noteEditMode = !this.noteEditMode;
this.renderer.invokeElementMethod(this.taskNoteRef.nativeElement,'focus');
}
// ------ THE COMPONENT
<span class="the-insert">
<form [hidden]="!noteEditMode && todo.note">
<textarea #tasknoteId id="tasknote"
name="tasknote"
[(ngModel)]="todo.note"
placeholder="{{ notePlaceholder }}"
style="background-color:pink"
(blur)="updateNote()" (click)="toggleNoteEditMode()"
[autofocus]="noteEditMode"
[innerHTML]="todo.note">
</textarea>
</form>
</span>
Run Code Online (Sandbox Code Playgroud)
如何通过类,id,selectors(div > .my-i)和jQuery中的属性获取DOM元素?
例如:
<div class="myClass" style="width:200px">
<span id="pop">test</span>
<div>
<i>aaa</i>
<i class="my-i">bbb</i>
<i class="my-i">ccc</i>
</div>
Run Code Online (Sandbox Code Playgroud)
我需要得到:
什么是最好的方式?
angular ×2