-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(playground): add @query decorators example
- Loading branch information
Showing
9 changed files
with
617 additions
and
31 deletions.
There are no files selected for viewing
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { forwardRef,Component, Input,Inject,Host, OnChildrenChanged, AfterViewInit, OnDestroy } from 'ng-metadata/core'; | ||
import { TabsComponent } from './tabs'; | ||
|
||
@Component({ | ||
selector:'tabs-content-child', | ||
template:( | ||
`<h5>Tabs CONTENT child! #{{ $ctrl.id }}</h5>` | ||
) | ||
}) | ||
export class TabsContentComponent implements OnChildrenChanged,AfterViewInit, OnDestroy{ | ||
@Input() id: string; | ||
|
||
constructor( | ||
@Inject(forwardRef(()=>TabsComponent)) @Host() private tabs: TabsComponent | ||
){} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import * as angular from 'angular'; | ||
import { provide } from 'ng-metadata/core'; | ||
|
||
import { TabsComponent } from './tabs'; | ||
import { TabsChildComponent } from './viewChild'; | ||
import { TabsContentComponent } from './contentChild'; | ||
|
||
export const TabsModule = angular.module('myTabs',[]) | ||
.directive(...provide(TabsComponent)) | ||
.directive(...provide(TabsChildComponent)) | ||
.directive(...provide(TabsContentComponent)) | ||
.name |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { | ||
Inject, | ||
Host, | ||
Component, | ||
ViewChild, | ||
ViewChildren, | ||
ContentChild, | ||
ContentChildren, | ||
AfterViewChecked, | ||
AfterContentChecked, | ||
OnChildrenChanged | ||
} from 'ng-metadata/core'; | ||
import { TabsChildComponent } from './viewChild'; | ||
import { TabsContentComponent } from './contentChild'; | ||
|
||
@Component( { | ||
selector: 'tabs', | ||
template: ( | ||
`<div> | ||
<h4>Tabs!</h4> | ||
<button ng-click="$ctrl.addItem()">add viewChild</button> | ||
<tabs-child id="0"></tabs-child> | ||
<ul><li ng-repeat="item in $ctrl.items"> | ||
<tabs-child id="item"></tabs-child> | ||
<button ng-click="$ctrl.removeItem(item)">remove</button> | ||
</li></ul> | ||
<div ng-transclude=""></div> | ||
<hr> | ||
<h6>viewChildred</h6> | ||
<pre>{{ $ctrl.tabsChildren.length }}</pre> | ||
<h6>contentChildren</h6> | ||
<pre>{{ $ctrl.tabsContents.length }}</pre> | ||
</div>` | ||
), | ||
//directives: [ TabsChildComponent ], | ||
legacy: { | ||
transclude: true | ||
} | ||
} ) | ||
export class TabsComponent implements AfterViewChecked,AfterContentChecked,AfterContentInit,AfterViewInit{ | ||
|
||
@ViewChild( TabsChildComponent ) | ||
firstTabsChild: TabsChildComponent; | ||
|
||
@ViewChildren( TabsChildComponent ) | ||
tabsChildren: TabsChildComponent[]; | ||
|
||
@ViewChildren( 'h6' ) | ||
h6titles: ng.IAugmentedJQuery; | ||
|
||
@ContentChild( TabsContentComponent ) | ||
firstTabsContent: TabsContentComponent; | ||
|
||
@ContentChildren( TabsContentComponent ) | ||
tabsContents: TabsContentComponent[]; | ||
|
||
ngAfterViewInit(){ | ||
console.info('hello from prototype.ngAfterViewInit',this); | ||
console.log(this.h6titles); | ||
|
||
} | ||
ngAfterContentInit(){ | ||
console.info('hello from prototype.ngAfterContentInit',this); | ||
} | ||
ngAfterViewChecked(){ | ||
console.log('hello from prototype.ngAfterViewChecked'); | ||
} | ||
ngAfterContentChecked(){ | ||
console.log('hello from prototype.ngAfterContentChecked'); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
items = [11,22,33]; | ||
|
||
|
||
|
||
removeItem(item){ | ||
const idx = this.items.indexOf(item); | ||
if(idx!==-1){ | ||
this.items.splice(idx,1); | ||
} | ||
} | ||
|
||
addItem(){ | ||
const newId = this.items[this.items.length-1]+2; | ||
this.items.push(newId); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { forwardRef,Component, Input,Inject,Host, OnChildrenChanged, AfterViewInit, OnDestroy } from 'ng-metadata/core'; | ||
import { TabsComponent } from './tabs'; | ||
|
||
|
||
@Component({ | ||
selector:'tabs-child', | ||
template:( | ||
`<h5>Tabs child #{{ $ctrl.id }}!</h5>` | ||
) | ||
}) | ||
export class TabsChildComponent implements AfterViewInit, OnDestroy{ | ||
@Input() id:number; | ||
|
||
constructor( | ||
@Inject(forwardRef(()=>TabsComponent)) @Host() private tabs: TabsComponent | ||
){} | ||
|
||
|
||
} |
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 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
Oops, something went wrong.