Open artem-v-shamsutdinov opened 8 years ago
Guys, not sure if you'll be interested but I just implemented this for ourselves cause we really needed it:
` export function ViewChild( // childComponentConstructor:Function, // childComponentAs:string = '$ctrl' // ) {
function findChildComponent(currentScope:any):any { while (currentScope) { let currentComponent = currentScope[childComponentAs]; if (currentComponent && currentComponent.constructor === childComponentConstructor) { return currentComponent; } currentComponent = findChildComponent(currentScope.$$nextSibling); if (currentComponent) { return currentComponent; } currentScope = currentScope.$$childHead; } return null; } return function (target, propertyKey:string) { Object.defineProperty(target, propertyKey, { get: function () { if(!this.$scope) { throw `'private $scope' must be set on a component using @ViewChild decorator`; } return findChildComponent(this.$scope.$$childHead); }, set: function (val) { throw `Cannot override child component reference for ${propertyKey}}`; } }); } }
`
It can be used this way in a 1.5 Component:
@ViewChild(ChildComponent) test:ChildComponent;
Of course it is only usable once the child component is initialized.
Anyway it would be great if you could add something like this :)
Guys, not sure if you'll be interested but I just implemented this for ourselves cause we really needed it:
` export function ViewChild( // childComponentConstructor:Function, // childComponentAs:string = '$ctrl' // ) {
`
It can be used this way in a 1.5 Component:
@ViewChild(ChildComponent) test:ChildComponent;
Of course it is only usable once the child component is initialized.
Anyway it would be great if you could add something like this :)