2016-06-23 09:47:54 -07:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2016-08-05 13:32:04 -07:00
|
|
|
import {Component, EventEmitter, Input, NgModule, Output, forwardRef} from '@angular/core';
|
|
|
|
import {BrowserModule} from '@angular/platform-browser';
|
2016-04-28 17:50:03 -07:00
|
|
|
import {UpgradeAdapter} from '@angular/upgrade';
|
2016-06-16 09:56:14 -07:00
|
|
|
|
2016-10-23 16:21:18 +02:00
|
|
|
declare const angular: any;
|
2016-06-16 09:56:14 -07:00
|
|
|
|
2015-10-10 22:04:52 -07:00
|
|
|
|
2016-10-23 16:21:18 +02:00
|
|
|
const styles = [`
|
2015-10-10 22:04:52 -07:00
|
|
|
.border {
|
|
|
|
border: solid 2px DodgerBlue;
|
|
|
|
}
|
|
|
|
.title {
|
|
|
|
background-color: LightSkyBlue;
|
|
|
|
padding: .2em 1em;
|
|
|
|
font-size: 1.2em;
|
|
|
|
}
|
|
|
|
.content {
|
|
|
|
padding: 1em;
|
|
|
|
}
|
2016-08-05 09:56:53 -07:00
|
|
|
`];
|
2015-10-10 22:04:52 -07:00
|
|
|
|
2016-10-23 16:21:18 +02:00
|
|
|
const adapter = new UpgradeAdapter(forwardRef(() => Ng2AppModule));
|
|
|
|
const ng1module = angular.module('myExample', []);
|
2015-10-10 22:04:52 -07:00
|
|
|
|
2016-10-23 16:21:18 +02:00
|
|
|
ng1module.controller('Index', function($scope: any) { $scope.name = 'World'; });
|
2015-10-10 22:04:52 -07:00
|
|
|
|
2016-08-05 13:32:04 -07:00
|
|
|
ng1module.directive('ng1User', function() {
|
2015-10-10 22:04:52 -07:00
|
|
|
return {
|
|
|
|
scope: {handle: '@', reset: '&'},
|
|
|
|
template: `
|
|
|
|
User: {{handle}}
|
|
|
|
<hr>
|
|
|
|
<button ng-click="reset()">clear</button>`
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'pane',
|
|
|
|
template: `<div class="border">
|
|
|
|
<div class="title">{{title}}</div>
|
|
|
|
<div class="content"><ng-content></ng-content></div>
|
|
|
|
</div>`,
|
|
|
|
styles: styles
|
|
|
|
})
|
2019-02-01 14:27:13 +01:00
|
|
|
export class Pane {
|
2015-10-10 22:04:52 -07:00
|
|
|
@Input() title: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'upgrade-app',
|
|
|
|
template: `<div class="border">
|
|
|
|
<pane title="Title: {{user}}">
|
|
|
|
<table cellpadding="3">
|
|
|
|
<tr>
|
2019-02-01 14:51:13 +01:00
|
|
|
<td class="projected-content"><ng-content></ng-content></td>
|
2016-08-05 13:32:04 -07:00
|
|
|
<td><ng1-user [handle]="user" (reset)="reset.emit()"></ng1-user></td>
|
2015-10-10 22:04:52 -07:00
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</pane>
|
|
|
|
</div>`,
|
2016-08-05 13:32:04 -07:00
|
|
|
styles: styles
|
2015-10-10 22:04:52 -07:00
|
|
|
})
|
2019-02-01 14:27:13 +01:00
|
|
|
export class UpgradeApp {
|
2015-10-10 22:04:52 -07:00
|
|
|
@Input() user: string;
|
|
|
|
@Output() reset = new EventEmitter();
|
|
|
|
constructor() {}
|
|
|
|
}
|
|
|
|
|
2016-08-03 17:44:48 -07:00
|
|
|
@NgModule({
|
2016-08-05 13:32:04 -07:00
|
|
|
declarations: [Pane, UpgradeApp, adapter.upgradeNg1Component('ng1User')],
|
2019-02-01 14:27:13 +01:00
|
|
|
imports: [BrowserModule],
|
2016-08-03 17:44:48 -07:00
|
|
|
})
|
2019-02-01 14:27:13 +01:00
|
|
|
export class Ng2AppModule {
|
2016-08-05 13:32:04 -07:00
|
|
|
}
|
|
|
|
|
2016-08-03 17:44:48 -07:00
|
|
|
|
2015-10-10 22:04:52 -07:00
|
|
|
ng1module.directive('upgradeApp', adapter.downgradeNg2Component(UpgradeApp));
|
|
|
|
|
2019-02-01 14:27:13 +01:00
|
|
|
adapter.bootstrap(document.body, ['myExample']);
|