ngUpgraders / ng-forward

The default solution for those that want to write Angular 2.x style code in Angular 1.x
410 stars 36 forks source link

TypeError is emitted when no default value is set on @Input properties #132

Open mlegenhausen opened 8 years ago

mlegenhausen commented 8 years ago

Using

It should be document that you get an error if you try to assign to an input property without an default value:

@Component({
  selector: 'app',
  template: 'Hello {{ ctrl.value }}'
})
class App {
  // @Input() value; does not work cause the decorators transform will mark the property as not writeable if no initializer is given.
  @Input() value = null; // This works 
}
panjiesw commented 8 years ago

Shouldn't you use it like below?

...
@Input() value;
...

Input and any other decorator returns metadata Function i think...

mlegenhausen commented 8 years ago

Nice hint I forgot the ().

timkindberg commented 8 years ago

Did that fix it or is it still a bug?

mlegenhausen commented 8 years ago

The change was introduced to babel-transform-decorators-lagacy here: https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy/commit/9eefc328e3044e8a1bca0e829b8b18d1b90280e2

I don't think it is a bug it seems to a feature, but when following the documentation of ng-forward you get an error. I will open an issue at babel-transform-decorators-lagacy.

mlegenhausen commented 8 years ago

There is already an issue loganfsmyth/babel-plugin-transform-decorators-legacy#14.