How to insert text into input fields using js?


I am working on ionic framework. I want to know how to insert text into input label from local storage. I want to add text in username input box if data is stored locally .Here goes the code.

In login.html

<label class="item item-input item-stacked-label">
   <span class="input-label">Username</span>
   <input type="text" ng-model="xxx.user" id="userInput"  placeholder="Email or Phone">

In controller .js

var loadData1 =window.localStorage.getItem("data");
    var userInput=document.getElementById("userInput");
   if (window.localStorage.getItem("data") !== null){
        userInput.innerHTML =loadData1;


add the data to the model of the input.

for ex:

$ = {'user': '' , 'password': ''};

var loadData1 =window.localStorage.getItem("data");

if (loadData1 != null){
   $ = loadData1;
   console.log( $;

Answered By – Sajal

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published