Created
October 26, 2015 03:24
-
-
Save timkindberg/f66b608fcd329f697eec to your computer and use it in GitHub Desktop.
ng-forward ng1 migration (part 2 - alternative)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { bundle } from 'ng-forward'; | |
import { ComponentA } from './component-a'; | |
// We can create a bundled module from ComponentA | |
// You can then reference that module elsewhere for | |
// non-converted components and services | |
bundle('app', ComponentA); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, Inject } from 'ng-forward'; | |
import { ServiceA } from './service-a'; | |
// We converted this file in part 1 | |
// Now we have converted serviceA so we can use properly by | |
// adding it to our providers array (which ensures it is bundled with this component) | |
// We can also now reference it by object instead of string in the @Inject call | |
@Component({ | |
selector: 'component-a' | |
}) | |
@Inject(ServiceA) | |
export class ComponentA { | |
constructor(serviceA) { } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
angular.module('app') | |
.directive('componentB', function() { | |
return ['serviceB', function linkFn(serviceA){}] | |
}); | |
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from 'ng-forward'; | |
@Injectable() | |
export class ServiceA{ } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
angular.module('app') | |
.service('serviceB', function() {}); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment