2015-03-13 06:10:11 -04:00
|
|
|
import {
|
|
|
|
afterEach,
|
|
|
|
AsyncTestCompleter,
|
|
|
|
beforeEach,
|
|
|
|
ddescribe,
|
|
|
|
describe,
|
|
|
|
dispatchEvent,
|
|
|
|
el,
|
|
|
|
expect,
|
|
|
|
iit,
|
|
|
|
inject,
|
|
|
|
it,
|
|
|
|
queryView,
|
2015-03-19 06:35:48 -04:00
|
|
|
xit
|
2015-03-13 06:10:11 -04:00
|
|
|
} from 'angular2/test_lib';
|
2015-03-19 06:35:48 -04:00
|
|
|
import {DOM} from 'angular2/src/dom/dom_adapter';
|
2015-02-03 10:27:09 -05:00
|
|
|
|
2015-02-05 17:09:26 -05:00
|
|
|
import {Lexer, Parser, ChangeDetector, dynamicChangeDetection} from 'angular2/change_detection';
|
|
|
|
import {Compiler, CompilerCache} from 'angular2/src/core/compiler/compiler';
|
|
|
|
import {DirectiveMetadataReader} from 'angular2/src/core/compiler/directive_metadata_reader';
|
2015-01-30 03:43:21 -05:00
|
|
|
import {NativeShadowDomStrategy} from 'angular2/src/core/compiler/shadow_dom_strategy';
|
2015-02-12 08:44:59 -05:00
|
|
|
import {TemplateLoader} from 'angular2/src/core/compiler/template_loader';
|
2015-02-24 10:05:45 -05:00
|
|
|
import {ComponentUrlMapper} from 'angular2/src/core/compiler/component_url_mapper';
|
2015-04-02 12:52:00 -04:00
|
|
|
import {UrlResolver} from 'angular2/src/services/url_resolver';
|
2015-04-02 17:40:49 -04:00
|
|
|
import {StyleUrlResolver} from 'angular2/src/render/dom/shadow_dom/style_url_resolver';
|
2015-03-02 09:02:48 -05:00
|
|
|
import {CssProcessor} from 'angular2/src/core/compiler/css_processor';
|
2015-04-02 12:52:00 -04:00
|
|
|
import {EventManager, DomEventsPlugin} from 'angular2/src/render/dom/events/event_manager';
|
2015-03-19 16:12:16 -04:00
|
|
|
import {VmTurnZone} from 'angular2/src/core/zone/vm_turn_zone';
|
2015-02-24 10:05:45 -05:00
|
|
|
|
2015-02-24 09:32:44 -05:00
|
|
|
import {MockTemplateResolver} from 'angular2/src/mock/template_resolver_mock';
|
2015-02-12 08:44:59 -05:00
|
|
|
|
2015-02-05 17:09:26 -05:00
|
|
|
import {Injector} from 'angular2/di';
|
2015-02-12 08:44:59 -05:00
|
|
|
|
2015-03-19 16:12:16 -04:00
|
|
|
import {Component, Decorator, Template, PropertySetter} from 'angular2/angular2';
|
2015-02-24 14:59:10 -05:00
|
|
|
import {ControlGroupDirective, ControlDirective, Control, ControlGroup, OptionalControl,
|
2015-03-19 17:01:11 -04:00
|
|
|
ControlValueAccessor, RequiredValidatorDirective, CheckboxControlValueAccessor,
|
|
|
|
DefaultValueAccessor, Validators} from 'angular2/forms';
|
2015-02-04 14:45:33 -05:00
|
|
|
|
2015-02-03 10:27:09 -05:00
|
|
|
export function main() {
|
|
|
|
function detectChanges(view) {
|
|
|
|
view.changeDetector.detectChanges();
|
|
|
|
}
|
|
|
|
|
|
|
|
function compile(componentType, template, context, callback) {
|
2015-02-24 09:32:44 -05:00
|
|
|
var tplResolver = new MockTemplateResolver();
|
2015-02-24 10:05:45 -05:00
|
|
|
var urlResolver = new UrlResolver();
|
2015-02-12 08:44:59 -05:00
|
|
|
|
2015-02-04 14:45:33 -05:00
|
|
|
var compiler = new Compiler(dynamicChangeDetection,
|
2015-02-24 10:05:45 -05:00
|
|
|
new TemplateLoader(null, null),
|
2015-02-04 14:45:33 -05:00
|
|
|
new DirectiveMetadataReader(),
|
|
|
|
new Parser(new Lexer()),
|
|
|
|
new CompilerCache(),
|
2015-02-24 10:05:45 -05:00
|
|
|
new NativeShadowDomStrategy(new StyleUrlResolver(urlResolver)),
|
|
|
|
tplResolver,
|
|
|
|
new ComponentUrlMapper(),
|
2015-03-02 09:02:48 -05:00
|
|
|
urlResolver,
|
2015-03-03 05:32:19 -05:00
|
|
|
new CssProcessor(null)
|
2015-02-12 08:44:59 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
tplResolver.setTemplate(componentType, new Template({
|
|
|
|
inline: template,
|
2015-03-19 16:12:16 -04:00
|
|
|
directives: [ControlGroupDirective, ControlDirective, WrappedValue, RequiredValidatorDirective,
|
2015-03-19 17:01:11 -04:00
|
|
|
CheckboxControlValueAccessor, DefaultValueAccessor]
|
2015-02-12 08:44:59 -05:00
|
|
|
}));
|
2015-02-03 10:27:09 -05:00
|
|
|
|
2015-02-12 08:44:59 -05:00
|
|
|
compiler.compile(componentType).then((pv) => {
|
2015-03-19 16:12:16 -04:00
|
|
|
var eventManager = new EventManager([new DomEventsPlugin()], new FakeVmTurnZone());
|
|
|
|
var view = pv.instantiate(null, eventManager);
|
2015-03-12 00:11:39 -04:00
|
|
|
view.hydrate(new Injector([]), null, null, context, null);
|
2015-02-03 10:27:09 -05:00
|
|
|
detectChanges(view);
|
|
|
|
callback(view);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-03-19 17:01:11 -04:00
|
|
|
if (DOM.supportsDOMEvents()) {
|
|
|
|
describe("integration tests", () => {
|
|
|
|
it("should initialize DOM elements with the given form object", inject([AsyncTestCompleter], (async) => {
|
|
|
|
var ctx = new MyComp(new ControlGroup({
|
|
|
|
"login": new Control("loginValue")
|
|
|
|
}));
|
2015-02-03 10:27:09 -05:00
|
|
|
|
2015-03-19 17:01:11 -04:00
|
|
|
var t = `<div [control-group]="form">
|
2015-02-23 18:26:53 -05:00
|
|
|
<input type="text" control="login">
|
2015-02-03 10:27:09 -05:00
|
|
|
</div>`;
|
|
|
|
|
2015-03-19 17:01:11 -04:00
|
|
|
compile(MyComp, t, ctx, (view) => {
|
|
|
|
var input = queryView(view, "input")
|
|
|
|
expect(input.value).toEqual("loginValue");
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
2015-02-03 10:27:09 -05:00
|
|
|
|
2015-03-09 12:41:49 -04:00
|
|
|
it("should update the control group values on DOM change", inject([AsyncTestCompleter], (async) => {
|
|
|
|
var form = new ControlGroup({
|
|
|
|
"login": new Control("oldValue")
|
|
|
|
});
|
|
|
|
var ctx = new MyComp(form);
|
2015-02-03 10:27:09 -05:00
|
|
|
|
2015-03-09 12:41:49 -04:00
|
|
|
var t = `<div [control-group]="form">
|
|
|
|
<input type="text" control="login">
|
|
|
|
</div>`;
|
2015-02-03 10:27:09 -05:00
|
|
|
|
2015-03-09 12:41:49 -04:00
|
|
|
compile(MyComp, t, ctx, (view) => {
|
|
|
|
var input = queryView(view, "input")
|
2015-02-03 10:27:09 -05:00
|
|
|
|
2015-03-09 12:41:49 -04:00
|
|
|
input.value = "updatedValue";
|
|
|
|
dispatchEvent(input, "change");
|
2015-02-03 10:27:09 -05:00
|
|
|
|
2015-03-09 12:41:49 -04:00
|
|
|
expect(form.value).toEqual({"login": "updatedValue"});
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
2015-02-03 10:27:09 -05:00
|
|
|
|
2015-03-25 17:21:57 -04:00
|
|
|
it("should work with single controls", inject([AsyncTestCompleter], (async) => {
|
|
|
|
var control = new Control("loginValue");
|
|
|
|
var ctx = new MyComp(control);
|
|
|
|
|
|
|
|
var t = `<div><input type="text" [control]="form"></div>`;
|
|
|
|
|
|
|
|
compile(MyComp, t, ctx, (view) => {
|
|
|
|
var input = queryView(view, "input")
|
|
|
|
expect(input.value).toEqual("loginValue");
|
|
|
|
|
|
|
|
input.value = "updatedValue";
|
|
|
|
dispatchEvent(input, "change");
|
|
|
|
|
|
|
|
expect(control.value).toEqual("updatedValue");
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2015-03-19 17:01:11 -04:00
|
|
|
it("should update DOM elements when rebinding the control group", inject([AsyncTestCompleter], (async) => {
|
|
|
|
var form = new ControlGroup({
|
|
|
|
"login": new Control("oldValue")
|
|
|
|
});
|
|
|
|
var ctx = new MyComp(form);
|
2015-02-03 10:27:09 -05:00
|
|
|
|
2015-03-19 17:01:11 -04:00
|
|
|
var t = `<div [control-group]="form">
|
2015-02-23 18:26:53 -05:00
|
|
|
<input type="text" control="login">
|
2015-02-03 10:27:09 -05:00
|
|
|
</div>`;
|
|
|
|
|
2015-03-19 17:01:11 -04:00
|
|
|
compile(MyComp, t, ctx, (view) => {
|
|
|
|
ctx.form = new ControlGroup({
|
|
|
|
"login": new Control("newValue")
|
|
|
|
});
|
|
|
|
detectChanges(view);
|
2015-02-03 10:27:09 -05:00
|
|
|
|
2015-03-19 17:01:11 -04:00
|
|
|
var input = queryView(view, "input")
|
|
|
|
expect(input.value).toEqual("newValue");
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
2015-02-03 10:27:09 -05:00
|
|
|
|
2015-03-19 17:01:11 -04:00
|
|
|
it("should update DOM element when rebinding the control name", inject([AsyncTestCompleter], (async) => {
|
|
|
|
var ctx = new MyComp(new ControlGroup({
|
|
|
|
"one": new Control("one"),
|
|
|
|
"two": new Control("two")
|
|
|
|
}), "one");
|
2015-02-03 10:27:09 -05:00
|
|
|
|
2015-03-19 17:01:11 -04:00
|
|
|
var t = `<div [control-group]="form">
|
2015-02-23 18:26:53 -05:00
|
|
|
<input type="text" [control]="name">
|
2015-02-03 10:27:09 -05:00
|
|
|
</div>`;
|
|
|
|
|
2015-03-19 17:01:11 -04:00
|
|
|
compile(MyComp, t, ctx, (view) => {
|
|
|
|
var input = queryView(view, "input")
|
|
|
|
expect(input.value).toEqual("one");
|
2015-02-03 10:27:09 -05:00
|
|
|
|
2015-03-19 17:01:11 -04:00
|
|
|
ctx.name = "two";
|
|
|
|
detectChanges(view);
|
2015-02-03 10:27:09 -05:00
|
|
|
|
2015-03-19 17:01:11 -04:00
|
|
|
expect(input.value).toEqual("two");
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
2015-02-04 14:45:33 -05:00
|
|
|
|
2015-03-09 12:41:49 -04:00
|
|
|
describe("different control types", () => {
|
2015-03-19 17:01:11 -04:00
|
|
|
it("should support <input type=text>", inject([AsyncTestCompleter], (async) => {
|
|
|
|
var ctx = new MyComp(new ControlGroup({"text": new Control("old")}));
|
2015-02-07 17:14:07 -05:00
|
|
|
|
2015-03-09 12:41:49 -04:00
|
|
|
var t = `<div [control-group]="form">
|
2015-03-19 17:01:11 -04:00
|
|
|
<input type="text" control="text">
|
2015-03-09 12:41:49 -04:00
|
|
|
</div>`;
|
2015-02-07 17:14:07 -05:00
|
|
|
|
2015-03-09 12:41:49 -04:00
|
|
|
compile(MyComp, t, ctx, (view) => {
|
|
|
|
var input = queryView(view, "input")
|
2015-03-19 17:01:11 -04:00
|
|
|
expect(input.value).toEqual("old");
|
2015-02-07 17:14:07 -05:00
|
|
|
|
2015-03-19 17:01:11 -04:00
|
|
|
input.value = "new";
|
|
|
|
dispatchEvent(input, "input");
|
|
|
|
|
|
|
|
expect(ctx.form.value).toEqual({"text": "new"});
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it("should support <input> without type", inject([AsyncTestCompleter], (async) => {
|
|
|
|
var ctx = new MyComp(new ControlGroup({"text": new Control("old")}));
|
|
|
|
|
|
|
|
var t = `<div [control-group]="form">
|
|
|
|
<input control="text">
|
|
|
|
</div>`;
|
|
|
|
|
|
|
|
compile(MyComp, t, ctx, (view) => {
|
|
|
|
var input = queryView(view, "input")
|
|
|
|
expect(input.value).toEqual("old");
|
|
|
|
|
|
|
|
input.value = "new";
|
|
|
|
dispatchEvent(input, "input");
|
2015-02-07 17:14:07 -05:00
|
|
|
|
2015-03-19 17:01:11 -04:00
|
|
|
expect(ctx.form.value).toEqual({"text": "new"});
|
2015-03-09 12:41:49 -04:00
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
2015-02-07 17:14:07 -05:00
|
|
|
|
2015-03-19 17:01:11 -04:00
|
|
|
it("should support <textarea>", inject([AsyncTestCompleter], (async) => {
|
2015-03-19 12:51:30 -04:00
|
|
|
var ctx = new MyComp(new ControlGroup({"text": new Control('old')}));
|
|
|
|
|
|
|
|
var t = `<div [control-group]="form">
|
|
|
|
<textarea control="text"></textarea>
|
|
|
|
</div>`;
|
|
|
|
|
|
|
|
compile(MyComp, t, ctx, (view) => {
|
|
|
|
var textarea = queryView(view, "textarea")
|
|
|
|
expect(textarea.value).toEqual("old");
|
|
|
|
|
|
|
|
textarea.value = "new";
|
2015-03-19 17:01:11 -04:00
|
|
|
dispatchEvent(textarea, "input");
|
2015-03-19 12:51:30 -04:00
|
|
|
|
2015-03-19 17:01:11 -04:00
|
|
|
expect(ctx.form.value).toEqual({"text": 'new'});
|
2015-03-19 12:51:30 -04:00
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2015-03-19 17:01:11 -04:00
|
|
|
it("should support <type=checkbox>", inject([AsyncTestCompleter], (async) => {
|
|
|
|
var ctx = new MyComp(new ControlGroup({"checkbox": new Control(true)}));
|
|
|
|
|
|
|
|
var t = `<div [control-group]="form">
|
|
|
|
<input type="checkbox" control="checkbox">
|
|
|
|
</div>`;
|
|
|
|
|
|
|
|
compile(MyComp, t, ctx, (view) => {
|
|
|
|
var input = queryView(view, "input")
|
|
|
|
expect(input.checked).toBe(true);
|
|
|
|
|
|
|
|
input.checked = false;
|
|
|
|
dispatchEvent(input, "change");
|
|
|
|
|
|
|
|
expect(ctx.form.value).toEqual({"checkbox": false});
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it("should support <select>", inject([AsyncTestCompleter], (async) => {
|
2015-03-19 13:06:56 -04:00
|
|
|
var ctx = new MyComp(new ControlGroup({"city": new Control("SF")}));
|
|
|
|
|
|
|
|
var t = `<div [control-group]="form">
|
|
|
|
<select control="city">
|
|
|
|
<option value="SF"></option>
|
|
|
|
<option value="NYC"></option>
|
|
|
|
</select>
|
|
|
|
</div>`;
|
|
|
|
|
|
|
|
compile(MyComp, t, ctx, (view) => {
|
|
|
|
var select = queryView(view, "select")
|
|
|
|
var sfOption = queryView(view, "option")
|
|
|
|
expect(select.value).toEqual('SF');
|
|
|
|
expect(sfOption.selected).toBe(true);
|
|
|
|
|
|
|
|
select.value = 'NYC';
|
|
|
|
dispatchEvent(select, "change");
|
|
|
|
|
2015-03-19 17:01:11 -04:00
|
|
|
expect(ctx.form.value).toEqual({"city": 'NYC'});
|
2015-03-19 13:06:56 -04:00
|
|
|
expect(sfOption.selected).toBe(false);
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2015-03-09 12:41:49 -04:00
|
|
|
it("should support custom value accessors", inject([AsyncTestCompleter], (async) => {
|
|
|
|
var ctx = new MyComp(new ControlGroup({"name": new Control("aa")}));
|
2015-02-07 17:14:07 -05:00
|
|
|
|
2015-03-09 12:41:49 -04:00
|
|
|
var t = `<div [control-group]="form">
|
|
|
|
<input type="text" control="name" wrapped-value>
|
|
|
|
</div>`;
|
2015-02-07 17:14:07 -05:00
|
|
|
|
2015-03-09 12:41:49 -04:00
|
|
|
compile(MyComp, t, ctx, (view) => {
|
|
|
|
var input = queryView(view, "input")
|
|
|
|
expect(input.value).toEqual("!aa!");
|
2015-02-07 17:14:07 -05:00
|
|
|
|
2015-03-09 12:41:49 -04:00
|
|
|
input.value = "!bb!";
|
|
|
|
dispatchEvent(input, "change");
|
2015-02-07 17:14:07 -05:00
|
|
|
|
2015-03-19 17:01:11 -04:00
|
|
|
expect(ctx.form.value).toEqual({"name": "bb"});
|
2015-03-09 12:41:49 -04:00
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
2015-02-07 17:14:07 -05:00
|
|
|
|
2015-03-09 12:41:49 -04:00
|
|
|
describe("validations", () => {
|
|
|
|
it("should use validators defined in html", inject([AsyncTestCompleter], (async) => {
|
|
|
|
var form = new ControlGroup({"login": new Control("aa")});
|
|
|
|
var ctx = new MyComp(form);
|
2015-02-04 14:45:33 -05:00
|
|
|
|
2015-03-09 12:41:49 -04:00
|
|
|
var t = `<div [control-group]="form">
|
|
|
|
<input type="text" control="login" required>
|
|
|
|
</div>`;
|
2015-02-04 14:45:33 -05:00
|
|
|
|
2015-03-09 12:41:49 -04:00
|
|
|
compile(MyComp, t, ctx, (view) => {
|
|
|
|
expect(form.valid).toEqual(true);
|
2015-02-04 14:45:33 -05:00
|
|
|
|
2015-03-09 12:41:49 -04:00
|
|
|
var input = queryView(view, "input");
|
2015-02-04 14:45:33 -05:00
|
|
|
|
2015-03-09 12:41:49 -04:00
|
|
|
input.value = "";
|
|
|
|
dispatchEvent(input, "change");
|
2015-02-04 14:45:33 -05:00
|
|
|
|
2015-03-09 12:41:49 -04:00
|
|
|
expect(form.valid).toEqual(false);
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
2015-02-04 14:45:33 -05:00
|
|
|
|
2015-03-09 12:41:49 -04:00
|
|
|
it("should use validators defined in the model", inject([AsyncTestCompleter], (async) => {
|
2015-03-19 17:21:40 -04:00
|
|
|
var form = new ControlGroup({"login": new Control("aa", Validators.required)});
|
2015-03-09 12:41:49 -04:00
|
|
|
var ctx = new MyComp(form);
|
2015-02-23 18:26:53 -05:00
|
|
|
|
2015-03-09 12:41:49 -04:00
|
|
|
var t = `<div [control-group]="form">
|
|
|
|
<input type="text" control="login">
|
|
|
|
</div>`;
|
2015-02-11 14:10:31 -05:00
|
|
|
|
2015-03-09 12:41:49 -04:00
|
|
|
compile(MyComp, t, ctx, (view) => {
|
|
|
|
expect(form.valid).toEqual(true);
|
2015-02-11 14:10:31 -05:00
|
|
|
|
2015-03-09 12:41:49 -04:00
|
|
|
var input = queryView(view, "input");
|
2015-02-11 14:10:31 -05:00
|
|
|
|
2015-03-09 12:41:49 -04:00
|
|
|
input.value = "";
|
|
|
|
dispatchEvent(input, "change");
|
2015-02-11 14:10:31 -05:00
|
|
|
|
2015-03-09 12:41:49 -04:00
|
|
|
expect(form.valid).toEqual(false);
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
2015-03-03 05:32:19 -05:00
|
|
|
|
2015-03-19 17:01:11 -04:00
|
|
|
describe("nested forms", () => {
|
|
|
|
it("should init DOM with the given form object", inject([AsyncTestCompleter], (async) => {
|
|
|
|
var form = new ControlGroup({
|
|
|
|
"nested": new ControlGroup({
|
|
|
|
"login": new Control("value")
|
|
|
|
})
|
|
|
|
});
|
|
|
|
var ctx = new MyComp(form);
|
2015-02-25 18:10:27 -05:00
|
|
|
|
2015-03-19 17:01:11 -04:00
|
|
|
var t = `<div [control-group]="form">
|
2015-02-25 18:10:27 -05:00
|
|
|
<div control-group="nested">
|
|
|
|
<input type="text" control="login">
|
|
|
|
</div>
|
|
|
|
</div>`;
|
|
|
|
|
2015-03-19 17:01:11 -04:00
|
|
|
compile(MyComp, t, ctx, (view) => {
|
|
|
|
var input = queryView(view, "input")
|
|
|
|
expect(input.value).toEqual("value");
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
2015-02-25 18:10:27 -05:00
|
|
|
|
2015-03-09 12:41:49 -04:00
|
|
|
it("should update the control group values on DOM change", inject([AsyncTestCompleter], (async) => {
|
|
|
|
var form = new ControlGroup({
|
|
|
|
"nested": new ControlGroup({
|
|
|
|
"login": new Control("value")
|
|
|
|
})
|
|
|
|
});
|
|
|
|
var ctx = new MyComp(form);
|
|
|
|
|
|
|
|
var t = `<div [control-group]="form">
|
|
|
|
<div control-group="nested">
|
|
|
|
<input type="text" control="login">
|
|
|
|
</div>
|
|
|
|
</div>`;
|
|
|
|
|
|
|
|
compile(MyComp, t, ctx, (view) => {
|
|
|
|
var input = queryView(view, "input")
|
|
|
|
|
|
|
|
input.value = "updatedValue";
|
|
|
|
dispatchEvent(input, "change");
|
|
|
|
|
2015-03-19 17:01:11 -04:00
|
|
|
expect(form.value).toEqual({"nested": {"login": "updatedValue"}});
|
2015-03-09 12:41:49 -04:00
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
2015-03-19 17:01:11 -04:00
|
|
|
});
|
2015-02-25 18:10:27 -05:00
|
|
|
});
|
2015-03-19 17:01:11 -04:00
|
|
|
}
|
2015-02-03 10:27:09 -05:00
|
|
|
}
|
|
|
|
|
2015-02-11 14:10:31 -05:00
|
|
|
@Component({
|
|
|
|
selector: "my-comp"
|
|
|
|
})
|
2015-02-03 10:27:09 -05:00
|
|
|
class MyComp {
|
2015-03-25 17:21:57 -04:00
|
|
|
form:any;
|
2015-02-03 10:27:09 -05:00
|
|
|
name:string;
|
|
|
|
|
2015-02-04 14:45:33 -05:00
|
|
|
constructor(form = null, name = null) {
|
2015-02-03 10:27:09 -05:00
|
|
|
this.form = form;
|
|
|
|
this.name = name;
|
|
|
|
}
|
2015-01-30 03:43:21 -05:00
|
|
|
}
|
2015-02-07 17:14:07 -05:00
|
|
|
|
2015-03-19 16:12:16 -04:00
|
|
|
|
|
|
|
@Decorator({
|
|
|
|
selector:'[wrapped-value]',
|
|
|
|
events: {
|
|
|
|
'change' : 'handleOnChange($event.target.value)'
|
2015-02-07 17:14:07 -05:00
|
|
|
}
|
2015-03-19 16:12:16 -04:00
|
|
|
})
|
2015-03-19 17:01:11 -04:00
|
|
|
class WrappedValue {
|
2015-03-19 16:12:16 -04:00
|
|
|
_setProperty:Function;
|
|
|
|
onChange:Function;
|
2015-02-07 17:14:07 -05:00
|
|
|
|
2015-03-19 16:12:16 -04:00
|
|
|
constructor(cd:ControlDirective, @PropertySetter('value') setProperty:Function) {
|
|
|
|
this._setProperty = setProperty;
|
|
|
|
cd.valueAccessor = this;
|
2015-02-07 17:14:07 -05:00
|
|
|
}
|
|
|
|
|
2015-03-19 16:12:16 -04:00
|
|
|
writeValue(value) {
|
|
|
|
this._setProperty(`!${value}!`);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleOnChange(value) {
|
|
|
|
this.onChange(value.substring(1, value.length - 1));
|
2015-02-07 17:14:07 -05:00
|
|
|
}
|
2015-02-12 08:44:59 -05:00
|
|
|
}
|
2015-03-19 16:12:16 -04:00
|
|
|
|
|
|
|
class FakeVmTurnZone extends VmTurnZone {
|
|
|
|
constructor() {
|
|
|
|
super({enableLongStackTrace: false});
|
|
|
|
}
|
|
|
|
|
|
|
|
run(fn) {
|
|
|
|
fn();
|
|
|
|
}
|
|
|
|
|
|
|
|
runOutsideAngular(fn) {
|
|
|
|
fn();
|
|
|
|
}
|
|
|
|
}
|