4
Besides this mask I tried to use two others that resulted in the same error, which is the following:
ERROR Error: Uncaught (in promise): Error: More than one custom value accessor matches form control with unspecified name attribute
Error: More than one custom value accessor matches form control with unspecified name attribute
This is the item that contains the problem:
<ion-item>
<ion-label color="primary" position = "floating" >CPF</ion-label>
<ion-input [(ngModel)] = "usuario.cpf" [brmasker]="000.000.000-00"></ion-input>
</ion-item>
Module :
@NgModule({
imports: [
CommonModule,
FormsModule,
IonicModule,
RouterModule.forChild(routes),
BrMaskerModule
],
declarations: [CadastrarPage]
})
follows the complete Typescript as requested:
import { Component, OnInit } from '@angular/core';
import { ModalController, AlertController } from '@ionic/angular';
import { UsuarioService } from 'src/app/services/usuario.service';
@Component({
selector: 'app-cadastrar',
templateUrl: './cadastrar.page.html',
styleUrls: ['./cadastrar.page.scss'],
})
export class CadastrarPage implements OnInit {
resultado : any = {
nome : false,
apelido : false,
sexo : false,
estado_civil : false,
email : false,
cpf : false,
celular : false,
dt_nascimento : false,
password : false
}
usuario : any = {}
constructor(
private modalCtrl : ModalController,
private usuarioService : UsuarioService,
private alertController : AlertController
) { }
ngOnInit() {
}
fechar()
{
this.modalCtrl.dismiss()
}
async cadastrar()
{
const alert = await this.alertController.create({
header: 'ERRO',
message: 'Houve um erro, tente nvoamente mais tarde.',
buttons: ['OK']
})
this.usuarioService.incluir(this.usuario).subscribe(
data => {
if(data.status == 200)
{
this.resultado = data.body
}
},
err => {
alert.present()
}
)
}
}
and HTML :
<ion-header>
<ion-toolbar>
<ion-title>cadastrar</ion-title>
<ion-button (click)="fechar()" icon-only><ion-icon name="arrow-back"></ion-icon></ion-button>
</ion-toolbar>
</ion-header>
<ion-content padding>
<ion-item>
<ion-label color="primary" position = "floating" >Nome</ion-label>
<ion-input name="nome" [(ngModel)] = "usuario.nome" name="nome"></ion-input>
</ion-item>
<div *ngIf ="resultado.nome">
<ion-label color="danger">{{resultado.nome}}</ion-label>
</div>
<ion-item>
<ion-label color="primary" position = "floating" >Apelido</ion-label>
<ion-input name="apelido" [(ngModel)] = "usuario.apelido"></ion-input>
</ion-item>
<div *ngIf ="resultado.apelido">
<ion-label color="danger">{{resultado.apelido}}</ion-label>
</div>
<ion-item>
<ion-label color="primary" position = "floating" >Sexo</ion-label>
<ion-input name="sexo" [(ngModel)] = "usuario.sexo"></ion-input>
</ion-item>
<div *ngIf ="resultado.sexo">
<ion-label color="danger">{{resultado.sexo}}</ion-label>
</div>
<ion-item>
<ion-label color="primary" position = "floating" >Estado Civil</ion-label>
<ion-input name="estado_civil" [(ngModel)] = "usuario.estado_civil"></ion-input>
</ion-item>
<div *ngIf ="resultado.estado_civil">
<ion-label color="danger">{{resultado.estado_civil}}</ion-label>
</div>
<ion-item>
<ion-label color="primary" position = "floating">E-mail</ion-label>
<ion-input name="email" [(ngModel)] = "usuario.email"></ion-input>
</ion-item>
<div *ngIf ="resultado.email">
<ion-label color="danger">{{resultado.email}}</ion-label>
</div>
<ion-item>
<ion-label color="primary" position = "floating" >CPF</ion-label>
<ion-input name="cpf" [(ngModel)] = "usuario.cpf" [brmasker]="000.000.000-00"></ion-input>
</ion-item>
<div *ngIf ="resultado.cpf">
<ion-label color="danger">{{resultado.cpf}}</ion-label>
</div>
<ion-item>
<ion-label color="primary" position = "floating" >Celular</ion-label>
<ion-input name="celular" [(ngModel)] = "usuario.celular"></ion-input>
</ion-item>
<div *ngIf ="resultado.celular">
<ion-label color="danger">{{resultado.celular}}</ion-label>
</div>
<ion-item>
<ion-label color="primary" position="floating">Data de Nascimneto</ion-label>
<ion-datetime name="dt_nascimento" [(ngModel)] = "usuario.dt_nascimento" displayFormat="DD/MM/YYYY" min="1994-03-14" max="2012-12-09" value=""></ion-datetime>
</ion-item>
<div *ngIf ="resultado.dt_nascimento">
<ion-label color="danger">{{resultado.dt_nascimento}}</ion-label>
</div>
<ion-item>
<ion-label color="primary" position="floating">Senha</ion-label>
<ion-input name="password" [(ngModel)]="usuario.password" type="password"></ion-input>
</ion-item>
<div *ngIf="resultado.senha">
<ion-label color="danger">{{resultado.password}}</ion-label>
</div>
<ion-button (click)="cadastrar()">Cadastrar</ion-button>
</ion-content>
Note: if I use [brmasker] in an input without ngModel on this page, it works perfectly
And your file TS is as?
– LeAndrade
That is why I asked to show your TS, you are not using the plugin as the documentation recommends, the correct is to use Formcontrol or else use the previous version of the plugin as Vinicius said in the answer below.
– LeAndrade