Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(reflection_capability): make injection work on inherited directives #12892

Closed
wants to merge 4 commits into from

Conversation

lacolaco
Copy link
Contributor

superseded #8991

hannahhoward and others added 3 commits June 2, 2016 23:21
… 2 Components/Directives

Makes it DI work when inheriting Components/Directives/Services from built-in Angular 2
Components/Directives/Services while using standard typescript compiler
…d/angular into laco-inherit-injection

# Conflicts:
#	build.sh
#	modules/@angular/core/src/reflection/reflection_capabilities.ts
@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm.

@lacolaco
Copy link
Contributor Author

I want to squash commits in this PR, but if I do it original author will be disappeared. Can I do it or any good solutions?

_viewContainerRef: ViewContainerRef, _templateRef: TemplateRef<Object>,
myService: MyService) {
super(_viewContainerRef, _templateRef);
console.log(myService);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debug

@vicb
Copy link
Contributor

vicb commented Nov 15, 2016

Keep the original author first commit and squash your commits.

I think we should have more test, including low level ones:

  • Make sure a Component, Directive or Pipe decoration on a derived class override the decorator on the base class,
  • Make sure a Pipe, ... decorator on a derived class does not modify the original metadata,
  • Make sur Input and Output on from the base class does not affect the derived class,
  • There should be an integration that runs in both JiT and AoT mode - see angular/modules/@angular/compiler-cli/integrationtest

Thanks

@vicb vicb added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews action: review The PR is still awaiting reviews from at least one requested reviewer area: core Issues related to the framework runtime labels Nov 15, 2016
@hannahhoward
Copy link
Contributor

Hi everyone! Many apologies for my absence -- yes life has moved on and I donut have time to complete this. Can answer questions for whomever is taking on this work.

@vicb
Copy link
Contributor

vicb commented Nov 16, 2016

@hannahhoward mo pb, thanks for the initial work on this.

tbosch added a commit to tbosch/angular that referenced this pull request Nov 22, 2016
tbosch added a commit to tbosch/angular that referenced this pull request Nov 22, 2016
tbosch added a commit to tbosch/angular that referenced this pull request Nov 22, 2016
Inheritance Semantics:

Class Decorators:
1) list all decorators of all parent classes and of the class itself (in this order)
2) only use the last decorator of each kind (e.g. @component / ...)

Constructor parameters:
- if a class inherits from a parent class and does not declare
  a constructor, it inherits the parent class constructor,
  and with it the parameter metadata of that parent class.

Property / Method decorators:
1) per property / method, list all decorators of all parent classes and of the class itself
   (in this order)
2) per property, only use the last decorator of each kind (e.g. @input / ...)

Lifeclyce hooks:
Merge the lifecycle hooks of all parent classes and of the class itself

E.g. the following is a valid use of inheritance and it will
also inherit all metadata:

```
@directive(
class ParentDirective {
  constructor(someDep: SomeDep) {}  
}

class ChildDirective extends ParentDirective {}
```

Closes angular#11606
Closes angular#12892
tbosch added a commit to tbosch/angular that referenced this pull request Nov 22, 2016
Decorators:
1) list the decorators of the class and its parents in the ancestor first order
2) only use the last decorator of each kind (e.g. @component / ...)

Constructor parameters:
If a class inherits from a parent class and does not declare
a constructor, it inherits the parent class constructor,
and with it the parameter metadata of that parent class.

Lifecycle hooks:
Merge the lifecycle hooks of all parent classes and of the class itself

## Example

E.g. the following is a valid use of inheritance and it will
also inherit all metadata:

```
@directive({selector: 'someDir'})
class ParentDirective {
  constructor(someDep: SomeDep) {}
}

class ChildDirective extends ParentDirective {}
```

Closes angular#11606
Closes angular#12892
tbosch added a commit to tbosch/angular that referenced this pull request Nov 22, 2016
## Inheritance Semantics:

Decorators:
1) list the decorators of the class and its parents in the ancestor first order
2) only use the last decorator of each kind (e.g. @component / ...)

Constructor parameters:
If a class inherits from a parent class and does not declare
a constructor, it inherits the parent class constructor,
and with it the parameter metadata of that parent class.

Lifecycle hooks:
Follow the normal class inheritance model,
i.e. lifecycle hooks of parent classes will be called
even if the method is not overwritten in the child class.

## Example

E.g. the following is a valid use of inheritance and it will
also inherit all metadata:

```
@directive({selector: 'someDir'})
class ParentDirective {
  constructor(someDep: SomeDep) {}

  ngOnInit() {}
}

class ChildDirective extends ParentDirective {}
```

Closes angular#11606
Closes angular#12892
tbosch added a commit to tbosch/angular that referenced this pull request Nov 22, 2016
## Inheritance Semantics:

Decorators:
1) list the decorators of the class and its parents in the ancestor first order
2) only use the last decorator of each kind (e.g. @component / ...)

Constructor parameters:
If a class inherits from a parent class and does not declare
a constructor, it inherits the parent class constructor,
and with it the parameter metadata of that parent class.

Lifecycle hooks:
Follow the normal class inheritance model,
i.e. lifecycle hooks of parent classes will be called
even if the method is not overwritten in the child class.

## Example

E.g. the following is a valid use of inheritance and it will
also inherit all metadata:

```
@directive({selector: 'someDir'})
class ParentDirective {
  constructor(someDep: SomeDep) {}

  ngOnInit() {}
}

class ChildDirective extends ParentDirective {}
```

Closes angular#11606
Closes angular#12892
@lacolaco
Copy link
Contributor Author

@vicb Bosch seems started adding inheritance support into the compiler layer. so I think this PR is no longer needed. should I close here and wait for that?

#11606 (comment)

tbosch added a commit to tbosch/angular that referenced this pull request Nov 23, 2016
## Inheritance Semantics:

Decorators:
1) list the decorators of the class and its parents in the ancestor first order
2) only use the last decorator of each kind (e.g. @component / ...)

Constructor parameters:
If a class inherits from a parent class and does not declare
a constructor, it inherits the parent class constructor,
and with it the parameter metadata of that parent class.

Lifecycle hooks:
Follow the normal class inheritance model,
i.e. lifecycle hooks of parent classes will be called
even if the method is not overwritten in the child class.

## Example

E.g. the following is a valid use of inheritance and it will
also inherit all metadata:

```
@directive({selector: 'someDir'})
class ParentDirective {
  constructor(someDep: SomeDep) {}

  ngOnInit() {}
}

class ChildDirective extends ParentDirective {}
```

Closes angular#11606
Closes angular#12892
tbosch added a commit to tbosch/angular that referenced this pull request Nov 24, 2016
## Inheritance Semantics:

Decorators:
1) list the decorators of the class and its parents in the ancestor first order
2) only use the last decorator of each kind (e.g. @component / ...)

Constructor parameters:
If a class inherits from a parent class and does not declare
a constructor, it inherits the parent class constructor,
and with it the parameter metadata of that parent class.

Lifecycle hooks:
Follow the normal class inheritance model,
i.e. lifecycle hooks of parent classes will be called
even if the method is not overwritten in the child class.

## Example

E.g. the following is a valid use of inheritance and it will
also inherit all metadata:

```
@directive({selector: 'someDir'})
class ParentDirective {
  constructor(someDep: SomeDep) {}

  ngOnInit() {}
}

class ChildDirective extends ParentDirective {}
```

Closes angular#11606
Closes angular#12892
tbosch added a commit to tbosch/angular that referenced this pull request Nov 24, 2016
## Inheritance Semantics:

Decorators:
1) list the decorators of the class and its parents in the ancestor first order
2) only use the last decorator of each kind (e.g. @component / ...)

Constructor parameters:
If a class inherits from a parent class and does not declare
a constructor, it inherits the parent class constructor,
and with it the parameter metadata of that parent class.

Lifecycle hooks:
Follow the normal class inheritance model,
i.e. lifecycle hooks of parent classes will be called
even if the method is not overwritten in the child class.

## Example

E.g. the following is a valid use of inheritance and it will
also inherit all metadata:

```
@directive({selector: 'someDir'})
class ParentDirective {
  constructor(someDep: SomeDep) {}

  ngOnInit() {}
}

class ChildDirective extends ParentDirective {}
```

Closes angular#11606
Closes angular#12892
@mrgoos
Copy link

mrgoos commented Nov 26, 2016

Hey guys, any news on that?
Thanks.

tbosch added a commit to tbosch/angular that referenced this pull request Nov 28, 2016
## Inheritance Semantics:

Decorators:
1) list the decorators of the class and its parents in the ancestor first order
2) only use the last decorator of each kind (e.g. @component / ...)

Constructor parameters:
If a class inherits from a parent class and does not declare
a constructor, it inherits the parent class constructor,
and with it the parameter metadata of that parent class.

Lifecycle hooks:
Follow the normal class inheritance model,
i.e. lifecycle hooks of parent classes will be called
even if the method is not overwritten in the child class.

## Example

E.g. the following is a valid use of inheritance and it will
also inherit all metadata:

```
@directive({selector: 'someDir'})
class ParentDirective {
  constructor(someDep: SomeDep) {}

  ngOnInit() {}
}

class ChildDirective extends ParentDirective {}
```

Closes angular#11606
Closes angular#12892
tbosch added a commit to tbosch/angular that referenced this pull request Nov 28, 2016
## Inheritance Semantics:

Decorators:
1) list the decorators of the class and its parents in the ancestor first order
2) only use the last decorator of each kind (e.g. @component / ...)

Constructor parameters:
If a class inherits from a parent class and does not declare
a constructor, it inherits the parent class constructor,
and with it the parameter metadata of that parent class.

Lifecycle hooks:
Follow the normal class inheritance model,
i.e. lifecycle hooks of parent classes will be called
even if the method is not overwritten in the child class.

## Example

E.g. the following is a valid use of inheritance and it will
also inherit all metadata:

```
@directive({selector: 'someDir'})
class ParentDirective {
  constructor(someDep: SomeDep) {}

  ngOnInit() {}
}

class ChildDirective extends ParentDirective {}
```

Closes angular#11606
Closes angular#12892
tbosch added a commit to tbosch/angular that referenced this pull request Nov 28, 2016
## Inheritance Semantics:

Decorators:
1) list the decorators of the class and its parents in the ancestor first order
2) only use the last decorator of each kind (e.g. @component / ...)

Constructor parameters:
If a class inherits from a parent class and does not declare
a constructor, it inherits the parent class constructor,
and with it the parameter metadata of that parent class.

Lifecycle hooks:
Follow the normal class inheritance model,
i.e. lifecycle hooks of parent classes will be called
even if the method is not overwritten in the child class.

## Example

E.g. the following is a valid use of inheritance and it will
also inherit all metadata:

```
@directive({selector: 'someDir'})
class ParentDirective {
  constructor(someDep: SomeDep) {}

  ngOnInit() {}
}

class ChildDirective extends ParentDirective {}
```

Closes angular#11606
Closes angular#12892
@vsavkin vsavkin closed this in f5c8e09 Nov 28, 2016
@lacolaco lacolaco deleted the laco-inherit-injection branch November 29, 2016 06:25
@mlc-mlapis
Copy link
Contributor

@tbosch If I understand correctly "template/templateUrl" or "styles/styleUrls" on a base component are now ignored from a derived component point of view now.

I read all discussion about the problem (like https://docs.google.com/document/d/16D3U3wdDBMEncUUEXBxiCaI11SnhjBijggZGq8JMjP0) again and I still do not understand why there are difficulties on decission how to inherit "template/templateUrl" or "styles/styleUrls" between a base and a derived component.

What is wrong on the following rules?

  • If a derived component does not declare template or styles then both are taken from its base component, if exists,
  • if a derived component declares them (in any variant) then definitions are taken from this derived component on the same rules as it would be a normal (base) component.

That is all. A programmer who writes the code has the same chance to make a mistake and it does not matter whether it is on a base or on a derived component.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews action: review The PR is still awaiting reviews from at least one requested reviewer area: core Issues related to the framework runtime cla: no
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants