Angular 2 Form Validation Error “Unhandled Promise rejection: Cannot assign to a reference or variable!”

前端 未结 6 966
面向向阳花
面向向阳花 2020-12-11 15:22

App.component.html



        
6条回答
  •  醉梦人生
    2020-12-11 15:49

    This error occurs when you try to define a template reference variable with the same name of an existing variable, like for example in this case:

        @Component({
        selector: 'example',
        template: `
           
           
           `
        })
       export class AppComponent {
         name:string;
    
     }
    

    As you can see, there’s the template reference variable #name on the input and there’s also a variable called name on my class, this will cause the following error when you try to run the application:

       zone.js:355 Unhandled Promise rejection: Cannot assign to a 
       reference or variable! ; Zone:  ; Task: Promise.then ; Value: 
       Error: Cannot assign to a reference or variable!(…) Error: Cannot 
       assign to a reference or variable!
    

    the solution is to change the name of one of your variables.

提交回复
热议问题