ngUpgraders / ng-forward

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

way to convert constants and values #97

Closed david-gang closed 9 years ago

david-gang commented 9 years ago

We need a way to convert constants and values to the new syntax. As i understand values are supported

timkindberg commented 9 years ago

This exists via provide.

import {Component, Inject, provide} from 'ng-forward';

@Component({
  selector: 'app',
  providers: [
    provide('SomeValue', { useValue: 'foo' }),
    provide('SomeConst', { useConstant: 'bar' })
  ]
})
class App {}

@Inject('SomeValue', 'SomeConst')
class SomeOtherThing {
  constructor(someVal, someConst) {}
}
MikeRyanDev commented 9 years ago

Also note that you probably should avoid using provide('SomeConst', { useConstant: 'bar' }), especially if you are working in an ES6 environment. It would be better to do something like:

const someConst = 'foo';

provide('SomeConst', { useValue: someConst });