Error: Uncaught (in Promise): Typeerror: Cannot read Property 'name' of Undefined

Asked

Viewed 677 times

1

You are generating this error by entering the page.

Error: Uncaught (in Promise): Typeerror: Cannot read Property 'name' of Undefined Typeerror: Cannot read Property 'name' of Undefined at Object.Eval [as updateDirectives] (Addmenucomponent.html:8) at Object.debugUpdateDirectives [as updateDirectives] (core.es5.js:12613) checkAndUpdateView (core.js:12025) at callViewAction (core.es5.js:12340) at execComponentViewsAction (core.es5.js:12286) at checkAndUpdateView (core.es5.js:12031) at callWithDebugContext (core.es5.js:13013) at Object.debugCheckAndUpdateView [as checkAndUpdateView] (core.js:12553) Viewref_.webpackJsonp.../.. /.. /core/@angular/core.es5.js.Viewref_.detectChanges (core.es5.js:10122) at Routeroutlet.webpackJsonp.../.. /.. /router/@angular/router.es5.js.Routeroutlet.activateWith (router.es5.js:5346) at

I’m thinking that the code in the Angular that is giving this problem, I’m managing to save normally in the Postman.

This is my back-end in the wheel file, I did on Node Express

router.post('/admin-painel/addMenu', controller.postMenu);

This is my class of services at Angular;

adicionar(menu): Promise<Menu> {
    const headers = new Headers();
    headers.append('Content-Type', 'application/json');

    return this._http.post(this.url+'/admin-painel/addMenu',
        JSON.stringify(menu), { headers })
        .toPromise()
        .then(response => response.json());
}

This is my class of components;

salvar(form: FormControl) {
    this.menuAdminService.adicionar(this.menu)
    .then(() => {
        this.notificationService.notify(`Você excluiu o menu ${this.menu.name} com sucesso`);
        form.reset();       
    })
    .catch(ErrorHandler.handlerError)
}

And this is my HTML page;

<div class="col-lg-10">
  <h3>{{ title }}</h3>
  <form  novalidate autocomplete="off"  >
      <div class="col-sm-12 col-xs-12">
        <mt-input-container errorMessage="Campo obrigatório e com 5 caracteres"  label="Nome">
          <input class="form-control" name="name"  
          [(ngModel)]="menu.name" required minlength="5"  
          placeholder="Digite o nome do restaurante" >
      </mt-input-container> 
    </div>  
</form>

<div class="row">
    <div class="col-xs-12">
      <button   class="btn btn-success pull-right" 
       ><i class="fa fa-credit-card">
      </i> Salvar
      </button>
    </div>
  </div>
</div>
  • 1

    Probably menu this Undefined

  • @Eduardovargas our guy you’re right, hahahaha.

No answers

Browser other questions tagged

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