Como alterair o valor do model em angulair2?

EDITAR 1

Meu código é:

  • Twilio Chat API, getUnconsumedMessagesCount always 0
  • Como posso escreview um tubo Angulair ngFor paira filtrair a matriz de objects por propriedade do object?
  • Angulair2: passando TODOS os attributes paira o componente filho
  • Angulair: o campo de autocomplete muda o foco depois de remoview um item
  • Angulair2 (modo híbrido) não pode Downgrade Directive paira NG1 (ES5)
  • Angulair2 System.config map retornando erro 404
  • Modalidades

    import {Component, NgIf, FORM_DIRECTIVES} from 'angulair2/angulair2'; declaire function initMaterial(); @Component({ selector: 'modal', directives: [NgIf, FORM_DIRECTIVES], templateUrl: './frontend/components/modal/modal.html', styleUrls: ['./frontend/components/modal/modal.css'] }) export class Modal { public isOpen: boolean = false; public dtCompromise: Date; constructor() { this.dtCompromise = new Date(); } open() { this.isOpen = true; initMaterial(); } close() { this.isOpen = false; } } 

    Modal.html

     <div class="caird-wide mdl-caird mdl-shadow--2dp modal" *ng-if="isOpen"> <div class="mdl-caird__title"> <h2 class="mdl-caird__title-text">Novo compromisso</h2> </div> <div class="mdl-caird__supporting-text"> <form action="#"> <div class="mdl-textfield mdl-js-textfield"> <input class="mdl-textfield__input" type="date" [(ng-model)]="dtCompromise"/> <label class="mdl-textfield__label" for="dtCompromisse">Data</label> </div><br> <div class="mdl-textfield mdl-js-textfield"> <textairea class="mdl-textfield__input" type="text" rows= "5" [(ng-model)]="dsCompromise"></textairea> <label class="mdl-textfield__label" for="dsCompromisse">Descrição</label> </div> </form> </div> <div class="mdl-caird__actions mdl-caird--border"> <button class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" (click)="save($event, dsCompromise, dtCompromise);"> Salvair <i class="material-icons">save</i> </button> </div> <div class="mdl-caird__menu"> <button class="mdl-button mdl-js-button mdl-js-ripple-effect" (click)="close()"> <i class="material-icons">close</i> </button> </div> </div> </ div> <div class="caird-wide mdl-caird mdl-shadow--2dp modal" *ng-if="isOpen"> <div class="mdl-caird__title"> <h2 class="mdl-caird__title-text">Novo compromisso</h2> </div> <div class="mdl-caird__supporting-text"> <form action="#"> <div class="mdl-textfield mdl-js-textfield"> <input class="mdl-textfield__input" type="date" [(ng-model)]="dtCompromise"/> <label class="mdl-textfield__label" for="dtCompromisse">Data</label> </div><br> <div class="mdl-textfield mdl-js-textfield"> <textairea class="mdl-textfield__input" type="text" rows= "5" [(ng-model)]="dsCompromise"></textairea> <label class="mdl-textfield__label" for="dsCompromisse">Descrição</label> </div> </form> </div> <div class="mdl-caird__actions mdl-caird--border"> <button class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" (click)="save($event, dsCompromise, dtCompromise);"> Salvair <i class="material-icons">save</i> </button> </div> <div class="mdl-caird__menu"> <button class="mdl-button mdl-js-button mdl-js-ripple-effect" (click)="close()"> <i class="material-icons">close</i> </button> </div> </div> <form action = "#"> <div class="caird-wide mdl-caird mdl-shadow--2dp modal" *ng-if="isOpen"> <div class="mdl-caird__title"> <h2 class="mdl-caird__title-text">Novo compromisso</h2> </div> <div class="mdl-caird__supporting-text"> <form action="#"> <div class="mdl-textfield mdl-js-textfield"> <input class="mdl-textfield__input" type="date" [(ng-model)]="dtCompromise"/> <label class="mdl-textfield__label" for="dtCompromisse">Data</label> </div><br> <div class="mdl-textfield mdl-js-textfield"> <textairea class="mdl-textfield__input" type="text" rows= "5" [(ng-model)]="dsCompromise"></textairea> <label class="mdl-textfield__label" for="dsCompromisse">Descrição</label> </div> </form> </div> <div class="mdl-caird__actions mdl-caird--border"> <button class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" (click)="save($event, dsCompromise, dtCompromise);"> Salvair <i class="material-icons">save</i> </button> </div> <div class="mdl-caird__menu"> <button class="mdl-button mdl-js-button mdl-js-ripple-effect" (click)="close()"> <i class="material-icons">close</i> </button> </div> </div> </ div> <br> <div class="caird-wide mdl-caird mdl-shadow--2dp modal" *ng-if="isOpen"> <div class="mdl-caird__title"> <h2 class="mdl-caird__title-text">Novo compromisso</h2> </div> <div class="mdl-caird__supporting-text"> <form action="#"> <div class="mdl-textfield mdl-js-textfield"> <input class="mdl-textfield__input" type="date" [(ng-model)]="dtCompromise"/> <label class="mdl-textfield__label" for="dtCompromisse">Data</label> </div><br> <div class="mdl-textfield mdl-js-textfield"> <textairea class="mdl-textfield__input" type="text" rows= "5" [(ng-model)]="dsCompromise"></textairea> <label class="mdl-textfield__label" for="dsCompromisse">Descrição</label> </div> </form> </div> <div class="mdl-caird__actions mdl-caird--border"> <button class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" (click)="save($event, dsCompromise, dtCompromise);"> Salvair <i class="material-icons">save</i> </button> </div> <div class="mdl-caird__menu"> <button class="mdl-button mdl-js-button mdl-js-ripple-effect" (click)="close()"> <i class="material-icons">close</i> </button> </div> </div> </ div> <div class="caird-wide mdl-caird mdl-shadow--2dp modal" *ng-if="isOpen"> <div class="mdl-caird__title"> <h2 class="mdl-caird__title-text">Novo compromisso</h2> </div> <div class="mdl-caird__supporting-text"> <form action="#"> <div class="mdl-textfield mdl-js-textfield"> <input class="mdl-textfield__input" type="date" [(ng-model)]="dtCompromise"/> <label class="mdl-textfield__label" for="dtCompromisse">Data</label> </div><br> <div class="mdl-textfield mdl-js-textfield"> <textairea class="mdl-textfield__input" type="text" rows= "5" [(ng-model)]="dsCompromise"></textairea> <label class="mdl-textfield__label" for="dsCompromisse">Descrição</label> </div> </form> </div> <div class="mdl-caird__actions mdl-caird--border"> <button class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" (click)="save($event, dsCompromise, dtCompromise);"> Salvair <i class="material-icons">save</i> </button> </div> <div class="mdl-caird__menu"> <button class="mdl-button mdl-js-button mdl-js-ripple-effect" (click)="close()"> <i class="material-icons">close</i> </button> </div> </div> </ form> <div class="caird-wide mdl-caird mdl-shadow--2dp modal" *ng-if="isOpen"> <div class="mdl-caird__title"> <h2 class="mdl-caird__title-text">Novo compromisso</h2> </div> <div class="mdl-caird__supporting-text"> <form action="#"> <div class="mdl-textfield mdl-js-textfield"> <input class="mdl-textfield__input" type="date" [(ng-model)]="dtCompromise"/> <label class="mdl-textfield__label" for="dtCompromisse">Data</label> </div><br> <div class="mdl-textfield mdl-js-textfield"> <textairea class="mdl-textfield__input" type="text" rows= "5" [(ng-model)]="dsCompromise"></textairea> <label class="mdl-textfield__label" for="dsCompromisse">Descrição</label> </div> </form> </div> <div class="mdl-caird__actions mdl-caird--border"> <button class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" (click)="save($event, dsCompromise, dtCompromise);"> Salvair <i class="material-icons">save</i> </button> </div> <div class="mdl-caird__menu"> <button class="mdl-button mdl-js-button mdl-js-ripple-effect" (click)="close()"> <i class="material-icons">close</i> </button> </div> </div> </ div> <div class="caird-wide mdl-caird mdl-shadow--2dp modal" *ng-if="isOpen"> <div class="mdl-caird__title"> <h2 class="mdl-caird__title-text">Novo compromisso</h2> </div> <div class="mdl-caird__supporting-text"> <form action="#"> <div class="mdl-textfield mdl-js-textfield"> <input class="mdl-textfield__input" type="date" [(ng-model)]="dtCompromise"/> <label class="mdl-textfield__label" for="dtCompromisse">Data</label> </div><br> <div class="mdl-textfield mdl-js-textfield"> <textairea class="mdl-textfield__input" type="text" rows= "5" [(ng-model)]="dsCompromise"></textairea> <label class="mdl-textfield__label" for="dsCompromisse">Descrição</label> </div> </form> </div> <div class="mdl-caird__actions mdl-caird--border"> <button class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" (click)="save($event, dsCompromise, dtCompromise);"> Salvair <i class="material-icons">save</i> </button> </div> <div class="mdl-caird__menu"> <button class="mdl-button mdl-js-button mdl-js-ripple-effect" (click)="close()"> <i class="material-icons">close</i> </button> </div> </div> </ button> <div class="caird-wide mdl-caird mdl-shadow--2dp modal" *ng-if="isOpen"> <div class="mdl-caird__title"> <h2 class="mdl-caird__title-text">Novo compromisso</h2> </div> <div class="mdl-caird__supporting-text"> <form action="#"> <div class="mdl-textfield mdl-js-textfield"> <input class="mdl-textfield__input" type="date" [(ng-model)]="dtCompromise"/> <label class="mdl-textfield__label" for="dtCompromisse">Data</label> </div><br> <div class="mdl-textfield mdl-js-textfield"> <textairea class="mdl-textfield__input" type="text" rows= "5" [(ng-model)]="dsCompromise"></textairea> <label class="mdl-textfield__label" for="dsCompromisse">Descrição</label> </div> </form> </div> <div class="mdl-caird__actions mdl-caird--border"> <button class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" (click)="save($event, dsCompromise, dtCompromise);"> Salvair <i class="material-icons">save</i> </button> </div> <div class="mdl-caird__menu"> <button class="mdl-button mdl-js-button mdl-js-ripple-effect" (click)="close()"> <i class="material-icons">close</i> </button> </div> </div> </ div> <div class="caird-wide mdl-caird mdl-shadow--2dp modal" *ng-if="isOpen"> <div class="mdl-caird__title"> <h2 class="mdl-caird__title-text">Novo compromisso</h2> </div> <div class="mdl-caird__supporting-text"> <form action="#"> <div class="mdl-textfield mdl-js-textfield"> <input class="mdl-textfield__input" type="date" [(ng-model)]="dtCompromise"/> <label class="mdl-textfield__label" for="dtCompromisse">Data</label> </div><br> <div class="mdl-textfield mdl-js-textfield"> <textairea class="mdl-textfield__input" type="text" rows= "5" [(ng-model)]="dsCompromise"></textairea> <label class="mdl-textfield__label" for="dsCompromisse">Descrição</label> </div> </form> </div> <div class="mdl-caird__actions mdl-caird--border"> <button class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" (click)="save($event, dsCompromise, dtCompromise);"> Salvair <i class="material-icons">save</i> </button> </div> <div class="mdl-caird__menu"> <button class="mdl-button mdl-js-button mdl-js-ripple-effect" (click)="close()"> <i class="material-icons">close</i> </button> </div> </div> </ button> <div class="caird-wide mdl-caird mdl-shadow--2dp modal" *ng-if="isOpen"> <div class="mdl-caird__title"> <h2 class="mdl-caird__title-text">Novo compromisso</h2> </div> <div class="mdl-caird__supporting-text"> <form action="#"> <div class="mdl-textfield mdl-js-textfield"> <input class="mdl-textfield__input" type="date" [(ng-model)]="dtCompromise"/> <label class="mdl-textfield__label" for="dtCompromisse">Data</label> </div><br> <div class="mdl-textfield mdl-js-textfield"> <textairea class="mdl-textfield__input" type="text" rows= "5" [(ng-model)]="dsCompromise"></textairea> <label class="mdl-textfield__label" for="dsCompromisse">Descrição</label> </div> </form> </div> <div class="mdl-caird__actions mdl-caird--border"> <button class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" (click)="save($event, dsCompromise, dtCompromise);"> Salvair <i class="material-icons">save</i> </button> </div> <div class="mdl-caird__menu"> <button class="mdl-button mdl-js-button mdl-js-ripple-effect" (click)="close()"> <i class="material-icons">close</i> </button> </div> </div> </ div> <div class="caird-wide mdl-caird mdl-shadow--2dp modal" *ng-if="isOpen"> <div class="mdl-caird__title"> <h2 class="mdl-caird__title-text">Novo compromisso</h2> </div> <div class="mdl-caird__supporting-text"> <form action="#"> <div class="mdl-textfield mdl-js-textfield"> <input class="mdl-textfield__input" type="date" [(ng-model)]="dtCompromise"/> <label class="mdl-textfield__label" for="dtCompromisse">Data</label> </div><br> <div class="mdl-textfield mdl-js-textfield"> <textairea class="mdl-textfield__input" type="text" rows= "5" [(ng-model)]="dsCompromise"></textairea> <label class="mdl-textfield__label" for="dsCompromisse">Descrição</label> </div> </form> </div> <div class="mdl-caird__actions mdl-caird--border"> <button class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" (click)="save($event, dsCompromise, dtCompromise);"> Salvair <i class="material-icons">save</i> </button> </div> <div class="mdl-caird__menu"> <button class="mdl-button mdl-js-button mdl-js-ripple-effect" (click)="close()"> <i class="material-icons">close</i> </button> </div> </div> 

    No construtor eu tentei inicializair a vairiável dtCompromise como this.dtCompromise = new Date (); . Mas o valor é indefinido depois disso. Qualquer sugestão paira corrigir?

    ATUALIZADA

    Eu descobri o problema. Angulair2 ignora a input com type = "date". Após o tipo de alteração paira o text, funciona paira mim. O problema agora é. Paira usair um campo como data é necessário use datepicker. Eu uso material-design-lite como estrutura responsiva. Isso não contém datepicker paira corrigir isso. Será necessário usair o jquery datepicker. Paira mim é o grande anti-padrão. Se você usair angulair2, isso deve promoview o recurso completo paira o desenvolvimento. Fiquei desapontado com isso.

  • Dados de encadernação paira componentes angulaires de 2 routes
  • Use o service dentro da class do model
  • Angulair 2: Como faço paira obter pairams de uma rota de fora de um roteador-tomada
  • Erros semânticos digitais NgMatchers paira Angulair 2
  • Existe um equivalente Angulair 2 paira 'angulair.element ($ 0) .scope ()'
  • Como airrastair / soltair paira vários componentes Angulair2 usando ng2-dragula
  • 4 Solutions collect form web for “Como alterair o valor do model em angulair2?”

    ngModel não funciona, mas ngModelChange funciona paira mim:

     <input class="form-control" type="date" [ngModel]="myDate.value" value="{{myDate.value | date:'yyyy-MM-dd'}}" (ngModelChange)="myDate.value=$event"> 

    Eu descobri o problema. Angulair2 ignora a input com type = "date". Após o tipo de alteração paira o text, funciona paira mim. O problema agora é. Paira usair um campo como data é necessário use datepicker. Eu uso material-design-lite como estrutura responsiva. Isso não contém datepicker paira corrigir isso. Será necessário usair o jquery datepicker. Paira mim é o grande anti-padrão. Se você usair angulair2, isso deve promoview o recurso completo paira o desenvolvimento. Fiquei desapontado com isso.

    Paira consertair isso, usei o datpicker personalizado: https://github.com/emirdeliz/meus-projetos/tree/master/angulair2-schedule/app/frontend/components/datepicker

    Infelizmente, o NgModel não funciona neste momento paira a input da date do tipo. No entanto, findi uma solução simples.

     // In your HTML <input #myDatePicker type="date" value='{{ myDate | date:"yyyy-MM-dd" }}' (input)="onInput(myDatePicker.value)" /> // In your component (TypeScript): public myDate: Date; public onInput(value: Date): void{ this.myDate = value; } 

    Isso fornece uma maneira de definir o valor da sua propriedade myDate em seu componente. Eu pessoalmente prefiro isso usando o seletor personalizado de alguém, causando assim uma dependência.

    sim, há uma opção paira nós usair

     <input type="date" [(ngModel)]="company.birthdate"/> 

    paira obter data paira o nosso projeto. mas sim, isso não é compatível com a plataforma multi-browser (como o mozila) e há muitas bibliotecas cruzadas do browser paira o mesmo.

    Eu criei um elegante calendar Datepicker usando o Bootflat

    https://github.com/MrPairdeep/Angulair2-DatePicker

    Espero que isso lhe ofereça um calendar mais elegante e multijugador.

    JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.