document.querySelector('.product_name') return an array, not an object.
You can try:
(document.querySelector('.product_name') as HTMLCollection)[0].innerText =
localStorage.getItem("product_name");
Btw, why don't you use product_name instead of
localStorage.getItem("product_name")
?
On Wednesday, July 1, 2020 at 4:40:36 AM UTC+7 [email protected] wrote:
> I am using a ControlValueAccessor to change my div tag to a form element
> and I am using localStorage to set and get my data. I am having the problem
> that my product_name item isn't being saved and after I refresh the page,
> the product_name disappears. How can I change my code so that the data
> persists after a page refresh?
>
> In the HTML template:
>
> <div class="product_name" name="p_name"></div>
> <div name="product_name" (click)="add('Bike')" style="cursor:pointer;">
> Bike</div>
>
>
> In the controller:
>
> add(product_name){
> localStorage.setItem("product_name", product_name);
> (document.querySelector('.product_name') as HTMLElement).innerText =
> localStorage.getItem("product_name");
> }
>
>
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/angular/bb889f51-1c88-4155-bc1a-a381353ef010n%40googlegroups.com.