Last active
September 4, 2016 06:18
-
-
Save joeeames/14833d37a663ecd552ceb663c33b86d4 to your computer and use it in GitHub Desktop.
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
// This is really strange. But you need the module when you create | |
// the upgrade adapter, but you also need the created upgrade adapter | |
// when creating the Module (see below, the call to upgradeNg1Component) | |
// so we use a forwardRef, and we have to put the upgradeAdapter and the | |
// module in the same file | |
export const upgradeAdapter = new UpgradeAdapter(forwardRef(() => AppModule)); | |
@NgModule({ | |
imports: [ | |
BrowserModule, | |
FormsModule, | |
HttpModule | |
], | |
declarations: [ | |
HomeComponent, | |
DetailPanelComponent, | |
CreateNewSessionComponent, | |
ProfileComponent, | |
SessionDetailWithVotesComponent, | |
upgradeAdapter.upgradeNg1Component('sessionDetail'), | |
UnreviewedTalkComponent, | |
NavComponent, | |
ZoomInDirective, | |
TalkDurationPipe | |
], | |
providers: [ | |
NameParser, Sessions, UnreviewedSessionCount | |
] | |
}) | |
export class AppModule { } |
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 { upgradeAdapter } from './app.module'; | |
import { NameParser } from './admin/nameParser.service'; | |
import { Sessions } from './sessions/sessions.service'; | |
import { ProfileComponent } from './profile/profile.component'; | |
import { UnreviewedTalkComponent } from './home/unreviewedTalk.component'; | |
import { CreateNewSessionComponent } from './home/createNewSession.component'; | |
import { DetailPanelComponent } from './common/detailPanel.component'; | |
import { HomeComponent } from './home/home.component'; | |
import { NavComponent } from './nav/nav.component'; | |
import { SessionDetailWithVotesComponent } from './sessions/sessionDetailWithVotes.component'; | |
import { SessionDetailComponent } from './sessions/sessionDetail.component'; | |
export function upgradeAndDowngrade() { | |
// Downgrading Angular 2 services to Angular 1 services | |
angular.module('app').factory('nameParser', upgradeAdapter.downgradeNg2Provider(NameParser)) | |
angular.module('app').factory('sessions', upgradeAdapter.downgradeNg2Provider(Sessions)) | |
angular.module('app').factory('unreviewedSessionCount', upgradeAdapter.downgradeNg2Provider(Sessions)) | |
// Upgrading Angular 1 services to Angular 2 services | |
upgradeAdapter.upgradeNg1Provider("currentIdentity"); | |
upgradeAdapter.upgradeNg1Provider("$location"); | |
upgradeAdapter.upgradeNg1Provider("toastr"); | |
// downgrading Angular 2 Components to Angular 1 Directives | |
angular.module('app').directive('profile', | |
<angular.IDirectiveFactory>upgradeAdapter.downgradeNg2Component(ProfileComponent)); | |
angular.module('app').directive('unreviewedTalk', | |
<angular.IDirectiveFactory>upgradeAdapter.downgradeNg2Component(UnreviewedTalkComponent)); | |
angular.module('app').directive('createNewSession', | |
<angular.IDirectiveFactory>upgradeAdapter.downgradeNg2Component(CreateNewSessionComponent)); | |
angular.module('app').directive('detailPanel', | |
<angular.IDirectiveFactory>upgradeAdapter.downgradeNg2Component(DetailPanelComponent)); | |
angular.module('app').directive('home', | |
<angular.IDirectiveFactory>upgradeAdapter.downgradeNg2Component(HomeComponent)); | |
angular.module('app').directive('nav', | |
<angular.IDirectiveFactory>upgradeAdapter.downgradeNg2Component(NavComponent)); | |
angular.module('app').directive('sessionDetailWithVotes', | |
<angular.IDirectiveFactory>upgradeAdapter.downgradeNg2Component(SessionDetailWithVotesComponent)); | |
angular.module('app').directive('sessionDetail', | |
<angular.IDirectiveFactory>upgradeAdapter.downgradeNg2Component(SessionDetailComponent)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment