javascript - How to solve out the $event issue in angular application when I'm using and Angular Material and some code

admin2025-04-09  0

I found an issue in Angular 6 version with that using Angular Material. Anybody can help me to fixed this error of $event.

 ERROR Error: Cannot assign value "$event" to template variable "nameValue". Template variables are read-only.
at _AstToIrVisitor.push../node_modules/@angular/piler/fesm5/piler.js._AstToIrVisitor.visitPropertyWrite (piler.js:8719)
at PropertyWrite.push../node_modules/@angular/piler/fesm5/piler.js.PropertyWrite.visit (piler.js:7589)
at convertActionBinding (piler.js:8320)
at prepareEventListenerParameters (piler.js:17473)
at Object.params (piler.js:18598)
at piler.js:18369
at Array.map (<anonymous>)
at piler.js:18369
at piler.js:17630
at Array.map (<anonymous>)

I found an issue in Angular 6 version with that using Angular Material. Anybody can help me to fixed this error of $event.

 ERROR Error: Cannot assign value "$event" to template variable "nameValue". Template variables are read-only.
at _AstToIrVisitor.push../node_modules/@angular/piler/fesm5/piler.js._AstToIrVisitor.visitPropertyWrite (piler.js:8719)
at PropertyWrite.push../node_modules/@angular/piler/fesm5/piler.js.PropertyWrite.visit (piler.js:7589)
at convertActionBinding (piler.js:8320)
at prepareEventListenerParameters (piler.js:17473)
at Object.params (piler.js:18598)
at piler.js:18369
at Array.map (<anonymous>)
at piler.js:18369
at piler.js:17630
at Array.map (<anonymous>)

I didn't use any template variable. I put it directly in the Html.

Unhandled Promise rejection: Cannot assign value "$event" to template variable "nameValue". Template variables are read-only. ; Zone: <root> ; Task: Promise.then ; Value: Error: Cannot assign value "$event" to template variable "nameValue". Template variables are read-only.
    at _AstToIrVisitor.push../node_modules/@angular/piler/fesm5/piler.js._AstToIrVisitor.visitPropertyWrite (piler.js:8719)
    at PropertyWrite.push../node_modules/@angular/piler/fesm5/piler.js.PropertyWrite.visit (piler.js:7589)
    at convertActionBinding (piler.js:8320)
    at prepareEventListenerParameters (piler.js:17473)
    at Object.params (piler.js:18598)
    at piler.js:18369
    at Array.map (<anonymous>)
    at piler.js:18369
    at piler.js:17630
    at Array.map (<anonymous>) Error: Cannot assign value "$event" to template variable "nameValue". Template variables are read-only.
    at _AstToIrVisitor.push../node_modules/@angular/piler/fesm5/piler.js._AstToIrVisitor.visitPropertyWrite (http://localhost:4200/vendor.js:39190:27)
    at PropertyWrite.push../node_modules/@angular/piler/fesm5/piler.js.PropertyWrite.visit (http://localhost:4200/vendor.js:38060:24)
    at convertActionBinding (http://localhost:4200/vendor.js:38791:45)
    at prepareEventListenerParameters (http://localhost:4200/vendor.js:47944:23)
    at Object.params (http://localhost:4200/vendor.js:49069:20)
    at http://localhost:4200/vendor.js:48840:90
    at Array.map (<anonymous>)
    at http://localhost:4200/vendor.js:48840:56
    at http://localhost:4200/vendor.js:48101:83
    at Array.map (<anonymous>)

Any solution for this

Share Improve this question asked May 29, 2020 at 5:13 AtiRadeonAtiRadeon 211 silver badge2 bronze badges 3
  • search your template, you must be having a variable declaration like "let nameValue" or "#nameValue" – Aakash Garg Commented May 29, 2020 at 5:51
  • 1 Please always include the relevant code snippet(s), because then we can provide exact answers – s.schleu Commented May 29, 2020 at 5:56
  • I think that the problem is that you has a error type code, you're using something event='what ever', must be event=='what ever' (two equals) – Eliseo Commented May 29, 2020 at 9:21
Add a ment  | 

1 Answer 1

Reset to default 9

I had the same problem with Angular 9. I figured out that I had declared a variable like "let nameValue of values" and after I did [(item)]=nameValue on the Template. The problem was I had assigned item to nameValue with double-binding. Removing the () solved my problem

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744128163a232557.html

最新回复(0)