docs: branding fixes (#14132)
Angular 1.x -> AngularJS Angular 1 -> AngularJS Angular1 -> AngularJS Angular 2+ -> Angular Angular 2.0 -> Angular Angular2 -> Angular I have deliberately not touched any of the symbol names as that would cause big merge collisions with Tobias's work. All the renames are in .md, .json, and inline comments and jsdocs. PR Close #14132
This commit is contained in:
@ -15,13 +15,13 @@ interface Hero {
|
||||
description: string;
|
||||
}
|
||||
|
||||
// #docregion Angular 2 Stuff
|
||||
// #docregion Angular Stuff
|
||||
// #docregion ng2-heroes
|
||||
// This Angular 2 component will be "downgraded" to be used in Angular 1
|
||||
// This Angular component will be "downgraded" to be used in AngularJS
|
||||
@Component({
|
||||
selector: 'ng2-heroes',
|
||||
// This template uses the upgraded `ng1-hero` component
|
||||
// Note that because its element is compiled by Angular 2+ we must use camelCased attribute names
|
||||
// Note that because its element is compiled by Angular we must use camelCased attribute names
|
||||
template: `<h1>Heroes</h1>
|
||||
<p><ng-content></ng-content></p>
|
||||
<div *ngFor="let hero of heroes">
|
||||
@ -37,7 +37,7 @@ class Ng2HeroesComponent {
|
||||
// #enddocregion
|
||||
|
||||
// #docregion ng2-heroes-service
|
||||
// This Angular 2 service will be "downgraded" to be used in Angular 1
|
||||
// This Angular service will be "downgraded" to be used in AngularJS
|
||||
@Injectable()
|
||||
class HeroesService {
|
||||
heroes: Hero[] = [
|
||||
@ -48,7 +48,7 @@ class HeroesService {
|
||||
|
||||
// #docregion use-ng1-upgraded-service
|
||||
constructor(@Inject('titleCase') titleCase: (v: string) => string) {
|
||||
// Change all the hero names to title case, using the "upgraded" Angular 1 service
|
||||
// Change all the hero names to title case, using the "upgraded" AngularJS service
|
||||
this.heroes.forEach((hero: Hero) => hero.name = titleCase(hero.name));
|
||||
}
|
||||
// #enddocregion
|
||||
@ -63,16 +63,16 @@ class HeroesService {
|
||||
// #enddocregion
|
||||
|
||||
// #docregion ng1-hero-wrapper
|
||||
// This Angular 2 directive will act as an interface to the "upgraded" Angular 1 component
|
||||
// This Angular directive will act as an interface to the "upgraded" AngularJS component
|
||||
@Directive({selector: 'ng1-hero'})
|
||||
class Ng1HeroComponentWrapper extends UpgradeComponent implements OnInit, OnChanges, DoCheck,
|
||||
OnDestroy {
|
||||
// The names of the input and output properties here must match the names of the
|
||||
// `<` and `&` bindings in the Angular 1 component that is being wrapped
|
||||
// `<` and `&` bindings in the AngularJS component that is being wrapped
|
||||
@Input() hero: Hero;
|
||||
@Output() onRemove: EventEmitter<void>;
|
||||
constructor(@Inject(ElementRef) elementRef: ElementRef, @Inject(Injector) injector: Injector) {
|
||||
// We must pass the name of the directive as used by Angular 1 to the super
|
||||
// We must pass the name of the directive as used by AngularJS to the super
|
||||
super('ng1Hero', elementRef, injector);
|
||||
}
|
||||
|
||||
@ -89,19 +89,19 @@ class Ng1HeroComponentWrapper extends UpgradeComponent implements OnInit, OnChan
|
||||
// #enddocregion
|
||||
|
||||
// #docregion ng2-module
|
||||
// This NgModule represents the Angular 2 pieces of the application
|
||||
// This NgModule represents the Angular pieces of the application
|
||||
@NgModule({
|
||||
declarations: [Ng2HeroesComponent, Ng1HeroComponentWrapper],
|
||||
providers: [
|
||||
HeroesService,
|
||||
// #docregion upgrade-ng1-service
|
||||
// Register an Angular 2+ provider whose value is the "upgraded" Angular 1 service
|
||||
// Register an Angular provider whose value is the "upgraded" AngularJS service
|
||||
{provide: 'titleCase', useFactory: (i: any) => i.get('titleCase'), deps: ['$injector']}
|
||||
// #enddocregion
|
||||
],
|
||||
// All components that are to be "downgraded" must be declared as `entryComponents`
|
||||
entryComponents: [Ng2HeroesComponent],
|
||||
// We must import `UpgradeModule` to get access to the Angular 1 core services
|
||||
// We must import `UpgradeModule` to get access to the AngularJS core services
|
||||
imports: [BrowserModule, UpgradeModule]
|
||||
})
|
||||
class Ng2AppModule {
|
||||
@ -114,12 +114,12 @@ class Ng2AppModule {
|
||||
|
||||
// #docregion Angular 1 Stuff
|
||||
// #docregion ng1-module
|
||||
// This Angular 1 module represents the Angular 1 pieces of the application
|
||||
// This Angular 1 module represents the AngularJS pieces of the application
|
||||
const ng1AppModule = angular.module('ng1AppModule', []);
|
||||
// #enddocregion
|
||||
|
||||
// #docregion ng1-hero
|
||||
// This Angular 1 component will be "upgraded" to be used in Angular 2+
|
||||
// This AngularJS component will be "upgraded" to be used in Angular
|
||||
ng1AppModule.component('ng1Hero', {
|
||||
bindings: {hero: '<', onRemove: '&'},
|
||||
transclude: true,
|
||||
@ -131,19 +131,19 @@ ng1AppModule.component('ng1Hero', {
|
||||
// #enddocregion
|
||||
|
||||
// #docregion ng1-title-case-service
|
||||
// This Angular 1 service will be "upgraded" to be used in Angular 2+
|
||||
// This AngularJS service will be "upgraded" to be used in Angular
|
||||
ng1AppModule.factory(
|
||||
'titleCase',
|
||||
() => (value: string) => value.replace(/((^|\s)[a-z])/g, (_, c) => c.toUpperCase()));
|
||||
// #enddocregion
|
||||
|
||||
// #docregion downgrade-ng2-heroes-service
|
||||
// Register an Angular 1 service, whose value is the "downgraded" Angular 2+ injectable.
|
||||
// Register an AngularJS service, whose value is the "downgraded" Angular injectable.
|
||||
ng1AppModule.factory('heroesService', downgradeInjectable(HeroesService));
|
||||
// #enddocregion
|
||||
|
||||
// #docregion ng2-heroes-wrapper
|
||||
// This is directive will act as the interface to the "downgraded" Angular 2+ component
|
||||
// This is directive will act as the interface to the "downgraded" Angular component
|
||||
ng1AppModule.directive(
|
||||
'ng2Heroes',
|
||||
downgradeComponent(
|
||||
@ -155,14 +155,14 @@ ng1AppModule.directive(
|
||||
// #docregion example-app
|
||||
// This is our top level application component
|
||||
ng1AppModule.component('exampleApp', {
|
||||
// We inject the "downgraded" HeroesService into this Angular 1 component
|
||||
// (We don't need the `HeroesService` type for Angular 1 DI - it just helps with TypeScript
|
||||
// We inject the "downgraded" HeroesService into this AngularJS component
|
||||
// (We don't need the `HeroesService` type for AngularJS DI - it just helps with TypeScript
|
||||
// compilation)
|
||||
controller: [
|
||||
'heroesService', function(heroesService: HeroesService) { this.heroesService = heroesService; }
|
||||
],
|
||||
// This template make use of the downgraded `ng2-heroes` component
|
||||
// Note that because its element is compiled by Angular 1 we must use kebab-case attributes for
|
||||
// Note that because its element is compiled by AngularJS we must use kebab-case attributes for
|
||||
// inputs and outputs
|
||||
template: `<link rel="stylesheet" href="./styles.css">
|
||||
<ng2-heroes [heroes]="$ctrl.heroesService.heroes" (add-hero)="$ctrl.heroesService.addHero()" (remove-hero)="$ctrl.heroesService.removeHero($event)">
|
||||
@ -174,10 +174,10 @@ ng1AppModule.component('exampleApp', {
|
||||
|
||||
|
||||
// #docregion bootstrap
|
||||
// First we bootstrap the Angular 2 HybridModule
|
||||
// First we bootstrap the Angular HybridModule
|
||||
// (We are using the dynamic browser platform as this example has not been compiled AoT)
|
||||
platformBrowserDynamic().bootstrapModule(Ng2AppModule).then(ref => {
|
||||
// Once Angular 2 bootstrap is complete then we bootstrap the Angular 1 module
|
||||
// Once Angular bootstrap is complete then we bootstrap the AngularJS module
|
||||
const upgrade = ref.injector.get(UpgradeModule) as UpgradeModule;
|
||||
upgrade.bootstrap(document.body, [ng1AppModule.name]);
|
||||
});
|
||||
|
Reference in New Issue
Block a user