Skip to content

Instantly share code, notes, and snippets.

@timkindberg
Last active October 25, 2015 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timkindberg/95166e525685db1f6394 to your computer and use it in GitHub Desktop.
Save timkindberg/95166e525685db1f6394 to your computer and use it in GitHub Desktop.
ng-forward ng1 migration (part 1)
import { componentAModule } from './component-a';
angular.module('app', [componentAModule]);
import { Component, Inject, bundle } from 'ng-forward';
// We'll convert componentA first
// Warning: Because we haven't converted serviceA yet,
// ComponentA will just have to trust that serviceA will be available
// We can inject serviceA by name using a string, which can reference any ng1 provider
@Component({
selector: 'component-a'
})
@Inject("serviceA")
export class ComponentA {
constructor(serviceA) { }
}
export default bundle('componentAModule', ComponentA).name;
(function() {
angular.module('app')
.directive('componentB', function() {
return ['serviceB', function linkFn(serviceA){}]
});
})()
(function() {
angular.module('app')
.service('serviceA', function() {});
})()
(function() {
angular.module('app')
.service('serviceB', function() {});
})()
@david-gang
Copy link

Hi,

There are a couple of things i want to ensure:

  • bundle can just be used once to bundle all components and not incrementally.
  • angular.module can be called multiple times

Shouldn't it be in service-a.js angular.module('componentAModule') ? I think the intention was to demonstrate that the module created by the bundle function can be called further through the angular.module syntax to register additional fields. Is this correct?

This would also enable us to migrate a big module in parts. Is this correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment