angular2
Version:
Angular 2 - a web framework for modern web apps
58 lines (57 loc) • 2.56 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
import { Directive, Self } from 'angular2/core';
import { NgControl } from './ng_control';
import { isPresent } from 'angular2/src/facade/lang';
/**
* Directive automatically applied to Angular forms that sets CSS classes
* based on control status (valid/invalid/dirty/etc).
*/
export let NgControlStatus = class NgControlStatus {
constructor(cd) {
this._cd = cd;
}
get ngClassUntouched() {
return isPresent(this._cd.control) ? this._cd.control.untouched : false;
}
get ngClassTouched() {
return isPresent(this._cd.control) ? this._cd.control.touched : false;
}
get ngClassPristine() {
return isPresent(this._cd.control) ? this._cd.control.pristine : false;
}
get ngClassDirty() {
return isPresent(this._cd.control) ? this._cd.control.dirty : false;
}
get ngClassValid() {
return isPresent(this._cd.control) ? this._cd.control.valid : false;
}
get ngClassInvalid() {
return isPresent(this._cd.control) ? !this._cd.control.valid : false;
}
};
NgControlStatus = __decorate([
Directive({
selector: '[ngControl],[ngModel],[ngFormControl]',
host: {
'[class.ng-untouched]': 'ngClassUntouched',
'[class.ng-touched]': 'ngClassTouched',
'[class.ng-pristine]': 'ngClassPristine',
'[class.ng-dirty]': 'ngClassDirty',
'[class.ng-valid]': 'ngClassValid',
'[class.ng-invalid]': 'ngClassInvalid'
}
}),
__param(0, Self()),
__metadata('design:paramtypes', [NgControl])
], NgControlStatus);