Get element by id - Angular2

后端 未结 4 1238
一整个雨季
一整个雨季 2020-12-29 18:31

I have a code:

document.getElementById(\'loginInput\').value = \'123\';

But while compiling the code I receive following error:

4条回答
  •  渐次进展
    2020-12-29 19:07

    A different approach, i.e: You could just do it 'the Angular way' and use ngModel and skip document.getElementById('loginInput').value = '123'; altogether. Instead:

    
    
    

    and in your component you give these values:

    username: 'whatever'
    password: 'whatever'
    

    this will preset the username and password upon navigating to page.

提交回复
热议问题