<!DOCTYPE html>
<html>
<head>
<base href="." />
<title>ng-bootstrap demo</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" />
<script src="https://unpkg.com/zone.js@^0.6.23/dist/zone.js"></script>
<script src="https://unpkg.com/zone.js@^0.6.23/dist/long-stack-trace-zone.js"></script>
<script src="https://unpkg.com/reflect-metadata@^0.1.8/Reflect.js"></script>
<script src="https://unpkg.com/systemjs@^0.19.40/dist/system.js"></script>
<script src="config.js"></script>
<script>
System.import('app').catch(console.error.bind(console));
</script>
</head>
<body>
<my-app>loading...</my-app>
</body>
</html>
var ver = {
ng: '2.0.0',
ngRouter: '3.0.0'
};
System.config({
//use typescript for compilation
transpiler: 'typescript',
//typescript compiler options
typescriptOptions: {
emitDecoratorMetadata: true
},
paths: {
'npm:': 'https://unpkg.com/'
},
map: {
'app': './src',
'@angular/core': 'npm:@angular/core@' + ver.ng + '/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common@' + ver.ng + '/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler@' + ver.ng + '/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser@' + ver.ng + '/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic@' + ver.ng + '/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http@' + ver.ng + '/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router@' + ver.ngRouter + '/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms@' + ver.ng + '/bundles/forms.umd.js',
'rxjs': 'npm:rxjs@5.0.0-beta.12',
'typescript': 'npm:typescript@2.0.10/lib/typescript.js',
'@ng-bootstrap/ng-bootstrap': 'npm:@ng-bootstrap/ng-bootstrap@1.0.0-alpha.18/bundles/ng-bootstrap.js'
},
packages: {
app: {
main: './main.ts',
defaultExtension: 'ts'
},
rxjs: {
defaultExtension: 'js'
}
}
});
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {AppModule} from './app';
platformBrowserDynamic().bootstrapModule(AppModule);
import { Component, NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule. FormControl, Validators } from '@angular/forms';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'my-app',
template: `
<form (ngSubmit)="submit()" #myForm="ngForm">
<!-- WITHOUT DATEPICKER -->
<label>Name: </label>
<input type="text"
id="name"
class="form-control"
required
minlength="4"
maxlength="24"
name="name"
[(ngModel)]="mymodel"
style="width:200px"
#name="ngModel" >
<div *ngIf="name.errors && (name.dirty || name.touched)"
class="alert alert-danger">
<div [hidden]="!name.errors.required">
Name is required
</div>
<div [hidden]="!name.errors.minlength">
Name must be at least 4 characters long.
</div>
<div [hidden]="!name.errors.maxlength">
Name cannot be more than 24 characters long.
</div>
</div>
<br>
<!-- WITH DATEPICKER -->
<label>Date: </label>
<input type="text"
id="date1"
style="width:200px"
class="form-control"
[formControl]="control"
required
name="date1"
[(ngModel)]="mymodel2"
(keyup)="manualValidation(dpTest)"
ngbDatepicker
#dpTest="ngbDatepicker">
<button (click)="dpTest.toggle()">
Cal
</button>
<div *ngIf="!control.valid" class="alert alert-danger">
<div>
Date is of an invalid format
</div>
</div>
<button type="submit">Submit</button>
</form>
`
})
export class App {
control: FormControl = new FormControl('date1', Validators.minLength(4));
mymodel2 = {year: 2000, month: 1, day: 1}
mymodel
constructor() {
this.mymodel = ""
}
manualValidation(dpTest) {
console.log("value of input field: "+dpTest._elRef.nativeElement.value)
console.log("control.valid before manual validation: "+this.control.valid)
if (dpTest._elRef.nativeElement.value.length < 4) {
this.control.setErrors({
"notMinLength": true
})
}
console.log("control.valid after manual validation: "+this.control.valid)
}
submit() {
console.log("submitted")
}
}
@NgModule({
imports: [BrowserModule, FormsModule, ReactiveFormsModule, NgbModule.forRoot()],
declarations: [App]
bootstrap: [App]
})
export class AppModule {}