Как решить проблему $ event в приложении angular, когда я использую и Angular Материал и некоторый код, настраивающий его - PullRequest
1 голос
/ 29 мая 2020

Я обнаружил проблему в версии Angular 6, в которой использовался Angular Материал. Кто-нибудь может помочь мне исправить эту ошибку $ event.

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

Я не использовал никакую переменную шаблона. Ставлю прямо в 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/compiler/fesm5/compiler.js._AstToIrVisitor.visitPropertyWrite (compiler.js:8719)
    at PropertyWrite.push../node_modules/@angular/compiler/fesm5/compiler.js.PropertyWrite.visit (compiler.js:7589)
    at convertActionBinding (compiler.js:8320)
    at prepareEventListenerParameters (compiler.js:17473)
    at Object.params (compiler.js:18598)
    at compiler.js:18369
    at Array.map (<anonymous>)
    at compiler.js:18369
    at compiler.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/compiler/fesm5/compiler.js._AstToIrVisitor.visitPropertyWrite (http://localhost:4200/vendor.js:39190:27)
    at PropertyWrite.push../node_modules/@angular/compiler/fesm5/compiler.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>)

Любое решение для этого

1 Ответ

3 голосов
/ 24 августа 2020

У меня была такая же проблема с Angular 9. Я понял, что объявил переменную типа "let nameValue of values", а после того, как сделал [(item)]=nameValue в шаблоне. Проблема заключалась в том, что я назначил item на nameValue с двойной привязкой. Удаление () решило мою проблему

...