Angular 5 - “Cannot read property of undefined”

后端 未结 5 972
终归单人心
终归单人心 2021-01-04 07:12

In Angular 5, for input



        
相关标签:
5条回答
  • 2021-01-04 07:31

    I am also getting same issue in my component.html file where I have defined the ngModel property to client.firstName, while you are creating object in component.ts file make sure object should be client. for example client : Client = { firstName:'', lastName:'', email:'', phone:'', balance:0 } Client is interface. small letter client is object which I mentioned in the component.html.

    0 讨论(0)
  • 2021-01-04 07:31

    Your techSpecMeta object do not have make property. Try initializing one in Init method.

    ngOnInit(){
    this.techSpecMeta= {make: ""};  }
    
    0 讨论(0)
  • 2021-01-04 07:45

    please try to intialize it as below description

    public techSpecMeta = <any> {};

    0 讨论(0)
  • 2021-01-04 07:48
    techSpecMeta: {};
    

    In Type script this means to declare a property of type {} with no value initialized. It is the same as:

    techSpecMeta: Object;
    

    You should instead be doing

    techSpecMeta = {};
    

    To make the binding work, you will need the property make as well.

    techSpecMeta = {make: null};
    

    Ideally you would create a class/interface for TechSpecMeta

    class TechSpecMeta {
        make: null;
        anotherProperty: null;
    }
    

    and use it in your component

    techSpecMeta = new TechSpecMeta();
    
    0 讨论(0)
  • 2021-01-04 07:49

    Please try to initialize it as below:

    techSpecMeta = {}
    
    0 讨论(0)
提交回复
热议问题