usando el cambio ng en angular 2 usando la variable modelo ng
¿Cómo puedo usar el evento ng-change en angular 2? Cada vez que se cambia la variable ng-model, se debe llamar a una función.
[(ngModel)]="variable"
ngchange=variable;
30
Author: BlockchainDeveloper, 2016-04-26
2 answers
Podrías usar el evento ngModelChange
:
[(ngModel)]="variable" (ngModelChange)="doSomething($event)"
Editar
De acuerdo con su comentario, creo que debe usar control de formularios con un validador personalizado.
Aquí hay una muestra:
@Component({
(...)
template: `
<input [(ngModel)]="variable" [ngFormControl]="ctrl"/>
`
})
export class SomeComponent {
constructor() {
this.ctrl = new Control('', (control) => {
// validate the value
});
this.ctrl.valueChanges.subscribe((value) => {
// called when the value is updated
});
}
}
Vea este artículo para más detalles:
61
Author: Thierry Templier,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-04-26 14:16:07
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-04-26 14:16:07
El componente tiene enlace bidireccional
- () para la salida
- [] para la entrada
Eso significa que puedes usar ==>[value] = "variable" (input)= " setVariable (event event)"
Evento.objetivo.valor
FYI = = > https://angular.io/docs/ts/latest/guide/user-input.html 7
Author: Navid Golforoushan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-04-19 23:17:34
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-04-19 23:17:34