2016-07-21 73 views
3

守則丁目瀏覽器的工作原理正確角2 +火狐+輸入+類型=日期日期選擇器不顯示

<div class="form-group"> 
    <label for="date">Date:</label> 
    <input class="form-control " [(ngModel)]="journal.record.date" type="date" required/> 
</div> 
<br/> 
<div class="form-group"> 
    <label for="timeEntered">Time Entered:</label> 
    <input class="form-control " [(ngModel)]="journal.record.entered" type="time" required/> 
</div> 

但Firefox並沒有顯示日期選擇器和timepicker

HTML包含:

<!-- 1. Load libraries --> 
<!-- Polyfill(s) for older browsers --> 
<script src="node_modules/core-js/client/shim.min.js"></script> 

或:

<!-- 1. Load libraries --> 
<!-- IE required polyfills, in this exact order --> 
<script src="node_modules/es6-shim/es6-shim.min.js"></script> 

它沒有幫助

我開始檢查WebShim enter link description here這是行不通的太

我怎樣才能改善這種問題?

+0

Firefox不支持日期和時間輸入類型 - http://www.w3schools.com/html/html_form_input_types.asp – Sanket

回答

0

這個工作,但它是很多額外的工作。也許我們很快會在angular中獲得一個。

的index.html

<script src="js/jquery-1.11.3.min.js"></script> 
<script src="js/modernizr-2.8.3.min.js"></script> 
<script src="js/webshim/minified/polyfiller.js"></script> 
<script> 
    webshim.setOptions('basePath', '/js/webshim/minified/shims/'); 
    // http://afarkas.github.io/webshim/demos/demos/cfgs/input-date.html#min=&max=&value=&list=&placeholder=&startView=2&minView=0&size=1&startValue=&useDecadeBase=0&calculateWidth=on&popover=&popover=&popover=&show-week=on 
    webshim.setOptions('forms', { 
     lazyCustomMessages: true, 
     addValidators: true, 
     extendNative: true 
    }); 
    webshim.setOptions('forms-ext', { 
     replaceUI: 'auto', 
     types: 'date', 
     date: { 
      startView: 2, 
      size: 1, 
      classes: 'hide-spinbtns' 
     } 
    }); 
    webshim.polyfill('forms forms-ext'); 
</script> 

app.module.ts

... 
import { WebshimPolyfill } from '../webshim-polyfill'; 

@NgModule({ 
    imports: [... 
    ], 
    declarations: [ 
     WebshimPolyfill, 
     ... 
    ], 
    bootstrap: [ 
     // The main app component 
     AppComponent 
    ] 
}) 
... 

webshim-polyfill.ts

import { Directive, AfterViewInit, Input, EventEmitter, ElementRef } from '@angular/core'; 

declare var webshim: any; 
declare var $: any; 


@Directive({ 
    selector: '[webshimPolyfill]', 
    outputs: ['ngModelChange'] 
}) 

export class WebshimPolyfill implements AfterViewInit { 
    private ngModelChange = new EventEmitter(); 
    @Input() validatevalue: Function; 
    @Input() thisarg; 

    constructor(private el: ElementRef) { } 

    ngAfterViewInit() { 
     let id = this.el.nativeElement.id; 
     $("#" + id).updatePolyfill(); 
     if (this.validatevalue) 
      $("#" + id).on('validatevalue', 
       (e: any, data: any) => { 
        return this.validatevalue.apply(this.thisarg, [e, data]); 
      }); 

     // this library creates a shadow dom element for <input type="date" 
     // do this if we want to work with the visible element 
     /* let elShadow = $("#" + id).getShadowElement()[0]; 
     * elShadow.onchange = (event) => { 
     */ 

     // don't use function(){} as this becomes the element not this 
     // and we cannot then ngModelChange.emit. 
     this.el.nativeElement.onchange = (event) => { 
      this.ngModelChange.emit(this.el.nativeElement.value); 
     }; 

     // (change) on <input> element doesn't work right now 
     // maybe 'export as' can fix that 
// https://medium.com/@NetanelBasal/angular-2-take-advantage-of-the-exportas-property-81374ce24d26#.jnpr99ncb 
    } 
    // webshim.setOptions is done in index.html as per webshims suggestion. 
} 

form.component.html

<input webshimPolyfill [validatevalue]="validDay" [thisarg]="thisarg" type="date" id="someDate" formControlName="someDate" [(ngModel)]="someDate" (change)="onChangeSomeDate();" > 
相關問題