2015-02-12 11:54:22 +01:00
|
|
|
import {Viewport} from 'angular2/src/core/annotations/annotations';
|
|
|
|
import {ViewContainer} from 'angular2/src/core/compiler/view_container';
|
2015-02-05 13:08:05 -08:00
|
|
|
import {isBlank} from 'angular2/src/facade/lang';
|
2014-12-17 10:01:08 +01:00
|
|
|
|
2015-02-12 11:54:22 +01:00
|
|
|
@Viewport({
|
2015-02-04 22:27:31 +01:00
|
|
|
selector: '[if]',
|
2014-12-17 10:01:08 +01:00
|
|
|
bind: {
|
2015-02-04 22:27:31 +01:00
|
|
|
'if': 'condition'
|
2014-12-17 10:01:08 +01:00
|
|
|
}
|
|
|
|
})
|
2015-02-04 22:27:31 +01:00
|
|
|
export class If {
|
2015-02-12 11:54:22 +01:00
|
|
|
viewContainer: ViewContainer;
|
2014-12-17 10:01:08 +01:00
|
|
|
prevCondition: boolean;
|
|
|
|
|
2015-02-12 11:54:22 +01:00
|
|
|
constructor(viewContainer: ViewContainer) {
|
|
|
|
this.viewContainer = viewContainer;
|
2014-12-17 10:01:08 +01:00
|
|
|
this.prevCondition = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
set condition(newCondition) {
|
|
|
|
if (newCondition && (isBlank(this.prevCondition) || !this.prevCondition)) {
|
|
|
|
this.prevCondition = true;
|
2015-02-12 11:54:22 +01:00
|
|
|
this.viewContainer.create();
|
2014-12-17 10:01:08 +01:00
|
|
|
} else if (!newCondition && (isBlank(this.prevCondition) || this.prevCondition)) {
|
|
|
|
this.prevCondition = false;
|
2015-02-12 11:54:22 +01:00
|
|
|
this.viewContainer.clear();
|
2014-12-17 10:01:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|