Created object id does not appear to be available in form

Asked

Viewed 25 times

0

I’m using Angular with Typescript and Asp.Net MVC.

I create an object and the MVC controller returns the object to me. I’m taking this object in Typescript and automatically the object ID goes to Form via Bind.

When I call the Submit method again, it seems that the Form has not received the Id. This Id will be used to let me know if I should give a post or a put.

I’m new to technology, someone can help me?

NOTE: after creating an object, I continue on the screen if the user wants to edit it. This is the best way to implement?

Follows the method:

submit(form){
    this.professor = form.value.htmlProfessor;

    if (this.professor.Id !=""){
      //aqui vou chamar o put
      console.log(this.professor.Id);
    }else{
      this.service.create(this.professor, 
        (response)=> {
          this.professor = response.json(); 
      });        
    }
  }
  • Your question is not clear and only this piece of code does not help in understanding the problem. It can be a little more specific?

  • Another thing: you’re using Angularjs with Typescript or Angular 2?

  • Sorry, I’ll try to be clearer. 1 - I have a teacher created in the database. This teacher is created and the MVC Controller gives me the answer (where the created object is). I take this object, and assign it to the teacher (this.professor = Sponse.json()). On the screen, I put the new teacher ID to be displayed and it is being displayed in an input (type="text"). If I, on the screen, click save, this method I put above runs again, however, the Id that is on the screen is blank within this method. I want to know how to get this Id in this case. 2 - Angular4 with Typescript.

  • "On the screen, I put the new teacher id". The id is returned by the server. I type nothing.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.