X Tutup
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions modules/angular2/src/forms/directives/ng_model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,25 @@ const formControlBinding = CONST_EXPR(new Binding(NgControl, {toAlias: forwardRe
exportAs: 'form'
})
export class NgModel extends NgControl {
control: Control;
ngModel: EventEmitter;
_control = new Control("");
_added = false;
ngModel = new EventEmitter();
model: any;
_added: boolean;

constructor() {
super();
this.control = new Control("");
this.ngModel = new EventEmitter();
this._added = false;
}

onChange(c) {
if (!this._added) {
setUpControl(this.control, this);
setUpControl(this._control, this);
this.control.updateValidity();
this._added = true;
};

if (StringMapWrapper.contains(c, "model")) {
this.control.updateValue(this.model);
this._control.updateValue(this.model);
}
}

get control() { return this._control; }

get path(): List<string> { return []; }

viewToModelUpdate(newValue: any): void { ObservableWrapper.callNext(this.ngModel, newValue); }
Expand Down
15 changes: 13 additions & 2 deletions modules/angular2/src/reflection/reflection_capabilities.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import {Type, isPresent, global, stringify, BaseException} from 'angular2/src/facade/lang';
import {
Type,
isPresent,
isFunction,
global,
stringify,
BaseException
} from 'angular2/src/facade/lang';
import {List, ListWrapper} from 'angular2/src/facade/collection';
import {GetterFn, SetterFn, MethodFn} from './types';
import {PlatformReflectionCapabilities} from 'platform_reflection_capabilities';
Expand Down Expand Up @@ -118,7 +125,11 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
annotations(typeOfFunc): List<any> {
// Prefer the direct API.
if (isPresent(typeOfFunc.annotations)) {
return typeOfFunc.annotations;
var annotations = typeOfFunc.annotations;
if (isFunction(annotations) && annotations.annotations) {
annotations = annotations.annotations;
}
return annotations;
}
if (isPresent(this._reflect) && isPresent(this._reflect.getMetadata)) {
var annotations = this._reflect.getMetadata('annotations', typeOfFunc);
Expand Down
8 changes: 8 additions & 0 deletions modules/angular2/test/core/annotations/decorators_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from 'angular2/test_lib';

import {Component, View, Directive} from 'angular2/angular2';
import {reflector} from 'angular2/src/reflection/reflection';

export function main() {
describe('es5 decorators', () => {
Expand All @@ -24,5 +25,12 @@ export function main() {
Component({}).View({}).View({}).Class({constructor: function() { this.works = true; }});
expect(new MyComponent().works).toEqual(true);
});

it('should create type in ES5', () => {
function MyComponent(){};
var as;
(<any>MyComponent).annotations = as = Component({}).View({});
expect(reflector.annotations(MyComponent)).toEqual(as.annotations);
});
});
}
X Tutup