angular6: I want my inherited component to have some propertys of the parent
up vote
7
down vote
favorite
I have a table where every table-cell is a different instance of a component. Depending on the data (date, text, links) I'm using different components.
As these components have a lot in common I introduced a TableCellMasterComponent which is extended by all other type of table-cells.
All my components have the same host property:
@Component({
selector: 'td[app-text-col]',
templateUrl: './text-col.component.html',
styleUrls: ['./text-col.component.css'],
host: {
"[hidden]": "col.deactivated"
},
changeDetection: ChangeDetectionStrategy.OnPush
})
export class TextColComponent extends TableCellMasterComponent{
}
Is it possible to somehow move this to the TableCellMasterComponent?
Also I would love to give all of them a contextmenu. But as I see it, it isn't possible to add HTML in the Master. Is that true?
Can I move the changeDetection to the Master?
angular inheritance components angular6
add a comment |
up vote
7
down vote
favorite
I have a table where every table-cell is a different instance of a component. Depending on the data (date, text, links) I'm using different components.
As these components have a lot in common I introduced a TableCellMasterComponent which is extended by all other type of table-cells.
All my components have the same host property:
@Component({
selector: 'td[app-text-col]',
templateUrl: './text-col.component.html',
styleUrls: ['./text-col.component.css'],
host: {
"[hidden]": "col.deactivated"
},
changeDetection: ChangeDetectionStrategy.OnPush
})
export class TextColComponent extends TableCellMasterComponent{
}
Is it possible to somehow move this to the TableCellMasterComponent?
Also I would love to give all of them a contextmenu. But as I see it, it isn't possible to add HTML in the Master. Is that true?
Can I move the changeDetection to the Master?
angular inheritance components angular6
Check out this blog post about Encapsulation. Maybe you'll find what you're looking for.
– ams
Nov 19 at 23:28
add a comment |
up vote
7
down vote
favorite
up vote
7
down vote
favorite
I have a table where every table-cell is a different instance of a component. Depending on the data (date, text, links) I'm using different components.
As these components have a lot in common I introduced a TableCellMasterComponent which is extended by all other type of table-cells.
All my components have the same host property:
@Component({
selector: 'td[app-text-col]',
templateUrl: './text-col.component.html',
styleUrls: ['./text-col.component.css'],
host: {
"[hidden]": "col.deactivated"
},
changeDetection: ChangeDetectionStrategy.OnPush
})
export class TextColComponent extends TableCellMasterComponent{
}
Is it possible to somehow move this to the TableCellMasterComponent?
Also I would love to give all of them a contextmenu. But as I see it, it isn't possible to add HTML in the Master. Is that true?
Can I move the changeDetection to the Master?
angular inheritance components angular6
I have a table where every table-cell is a different instance of a component. Depending on the data (date, text, links) I'm using different components.
As these components have a lot in common I introduced a TableCellMasterComponent which is extended by all other type of table-cells.
All my components have the same host property:
@Component({
selector: 'td[app-text-col]',
templateUrl: './text-col.component.html',
styleUrls: ['./text-col.component.css'],
host: {
"[hidden]": "col.deactivated"
},
changeDetection: ChangeDetectionStrategy.OnPush
})
export class TextColComponent extends TableCellMasterComponent{
}
Is it possible to somehow move this to the TableCellMasterComponent?
Also I would love to give all of them a contextmenu. But as I see it, it isn't possible to add HTML in the Master. Is that true?
Can I move the changeDetection to the Master?
angular inheritance components angular6
angular inheritance components angular6
asked Nov 9 at 10:09
NDDTConti
389
389
Check out this blog post about Encapsulation. Maybe you'll find what you're looking for.
– ams
Nov 19 at 23:28
add a comment |
Check out this blog post about Encapsulation. Maybe you'll find what you're looking for.
– ams
Nov 19 at 23:28
Check out this blog post about Encapsulation. Maybe you'll find what you're looking for.
– ams
Nov 19 at 23:28
Check out this blog post about Encapsulation. Maybe you'll find what you're looking for.
– ams
Nov 19 at 23:28
add a comment |
2 Answers
2
active
oldest
votes
up vote
4
down vote
accepted
The @Component
decorator metadata is not inherited so you cannot move some things to the base class. @Input
and @Output
properties get inherited.
There is a solution for the host property you can use a @HostBinding
instead and this will get inherited. For example your binding you can do like this:
@HostBinding('hidden') get hidden(): boolean { return col.deactivated; }
I tried this, the problem with this is that the property col.deactivated changes over time and with the old solution the columns would react to it. With this solution they don't. Sadly I can't bind to [hidden]
– NDDTConti
Nov 15 at 9:22
Can you give more information about where thecol.deactivated
comes from? I have made a simple sample on StackBlitz and it works ok. I'm binding to a property of the same component.
– AlesD
Nov 15 at 19:58
Yeah but in your example it is only checked on startup. There is no change later. On my example the col-object is handed in as an @Input
– NDDTConti
Nov 20 at 7:53
It changes if you press the Toggle button. Then you can see live that it updates the binding and the content is hidden or shown.
– AlesD
Nov 20 at 22:51
you are totally right and it also works, must have been tired when I tested this, thanks so much
– NDDTConti
Nov 21 at 8:47
add a comment |
up vote
2
down vote
I also created a Stackblitz which solves them the only way I know how. Credit to AlesD for solving your first problem, all you needed to do to solve the issue is add @Input()
onto visibility which you control in the parent element.
Your issue with a context menu is less straightforward. One option that I quickly tried to show in my stackblitz using ngx-contextmenu is done using nested components. There's a nice tutorial here
As you discovered, you have to choose between using extends, or using a nested component. In my example, I use both, but it may make the most sense to just use one or the other depending:
- If your context menus are different and redundancy is not that big an issue, use extends, and build the context menu manually on each component
- if the context menus are all going to be the same, I would drop the extends entirely and use a nested component. You can access the nested component using @ViewChild to gain access to the attributes you need.
- Using both (like in my example) was used mostly for demonstrating as I don't understand the whole context of your application, but if you could abstract your cells to use a common interface or class you can pass in to the contextMenu, limiting the number of inputs, it may make sense for you.
I would love to also award you a bounty, sadly I can only do that once, thanks so much for your help
– NDDTConti
Nov 21 at 8:47
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
The @Component
decorator metadata is not inherited so you cannot move some things to the base class. @Input
and @Output
properties get inherited.
There is a solution for the host property you can use a @HostBinding
instead and this will get inherited. For example your binding you can do like this:
@HostBinding('hidden') get hidden(): boolean { return col.deactivated; }
I tried this, the problem with this is that the property col.deactivated changes over time and with the old solution the columns would react to it. With this solution they don't. Sadly I can't bind to [hidden]
– NDDTConti
Nov 15 at 9:22
Can you give more information about where thecol.deactivated
comes from? I have made a simple sample on StackBlitz and it works ok. I'm binding to a property of the same component.
– AlesD
Nov 15 at 19:58
Yeah but in your example it is only checked on startup. There is no change later. On my example the col-object is handed in as an @Input
– NDDTConti
Nov 20 at 7:53
It changes if you press the Toggle button. Then you can see live that it updates the binding and the content is hidden or shown.
– AlesD
Nov 20 at 22:51
you are totally right and it also works, must have been tired when I tested this, thanks so much
– NDDTConti
Nov 21 at 8:47
add a comment |
up vote
4
down vote
accepted
The @Component
decorator metadata is not inherited so you cannot move some things to the base class. @Input
and @Output
properties get inherited.
There is a solution for the host property you can use a @HostBinding
instead and this will get inherited. For example your binding you can do like this:
@HostBinding('hidden') get hidden(): boolean { return col.deactivated; }
I tried this, the problem with this is that the property col.deactivated changes over time and with the old solution the columns would react to it. With this solution they don't. Sadly I can't bind to [hidden]
– NDDTConti
Nov 15 at 9:22
Can you give more information about where thecol.deactivated
comes from? I have made a simple sample on StackBlitz and it works ok. I'm binding to a property of the same component.
– AlesD
Nov 15 at 19:58
Yeah but in your example it is only checked on startup. There is no change later. On my example the col-object is handed in as an @Input
– NDDTConti
Nov 20 at 7:53
It changes if you press the Toggle button. Then you can see live that it updates the binding and the content is hidden or shown.
– AlesD
Nov 20 at 22:51
you are totally right and it also works, must have been tired when I tested this, thanks so much
– NDDTConti
Nov 21 at 8:47
add a comment |
up vote
4
down vote
accepted
up vote
4
down vote
accepted
The @Component
decorator metadata is not inherited so you cannot move some things to the base class. @Input
and @Output
properties get inherited.
There is a solution for the host property you can use a @HostBinding
instead and this will get inherited. For example your binding you can do like this:
@HostBinding('hidden') get hidden(): boolean { return col.deactivated; }
The @Component
decorator metadata is not inherited so you cannot move some things to the base class. @Input
and @Output
properties get inherited.
There is a solution for the host property you can use a @HostBinding
instead and this will get inherited. For example your binding you can do like this:
@HostBinding('hidden') get hidden(): boolean { return col.deactivated; }
answered Nov 14 at 22:15
AlesD
2,01827
2,01827
I tried this, the problem with this is that the property col.deactivated changes over time and with the old solution the columns would react to it. With this solution they don't. Sadly I can't bind to [hidden]
– NDDTConti
Nov 15 at 9:22
Can you give more information about where thecol.deactivated
comes from? I have made a simple sample on StackBlitz and it works ok. I'm binding to a property of the same component.
– AlesD
Nov 15 at 19:58
Yeah but in your example it is only checked on startup. There is no change later. On my example the col-object is handed in as an @Input
– NDDTConti
Nov 20 at 7:53
It changes if you press the Toggle button. Then you can see live that it updates the binding and the content is hidden or shown.
– AlesD
Nov 20 at 22:51
you are totally right and it also works, must have been tired when I tested this, thanks so much
– NDDTConti
Nov 21 at 8:47
add a comment |
I tried this, the problem with this is that the property col.deactivated changes over time and with the old solution the columns would react to it. With this solution they don't. Sadly I can't bind to [hidden]
– NDDTConti
Nov 15 at 9:22
Can you give more information about where thecol.deactivated
comes from? I have made a simple sample on StackBlitz and it works ok. I'm binding to a property of the same component.
– AlesD
Nov 15 at 19:58
Yeah but in your example it is only checked on startup. There is no change later. On my example the col-object is handed in as an @Input
– NDDTConti
Nov 20 at 7:53
It changes if you press the Toggle button. Then you can see live that it updates the binding and the content is hidden or shown.
– AlesD
Nov 20 at 22:51
you are totally right and it also works, must have been tired when I tested this, thanks so much
– NDDTConti
Nov 21 at 8:47
I tried this, the problem with this is that the property col.deactivated changes over time and with the old solution the columns would react to it. With this solution they don't. Sadly I can't bind to [hidden]
– NDDTConti
Nov 15 at 9:22
I tried this, the problem with this is that the property col.deactivated changes over time and with the old solution the columns would react to it. With this solution they don't. Sadly I can't bind to [hidden]
– NDDTConti
Nov 15 at 9:22
Can you give more information about where the
col.deactivated
comes from? I have made a simple sample on StackBlitz and it works ok. I'm binding to a property of the same component.– AlesD
Nov 15 at 19:58
Can you give more information about where the
col.deactivated
comes from? I have made a simple sample on StackBlitz and it works ok. I'm binding to a property of the same component.– AlesD
Nov 15 at 19:58
Yeah but in your example it is only checked on startup. There is no change later. On my example the col-object is handed in as an @Input
– NDDTConti
Nov 20 at 7:53
Yeah but in your example it is only checked on startup. There is no change later. On my example the col-object is handed in as an @Input
– NDDTConti
Nov 20 at 7:53
It changes if you press the Toggle button. Then you can see live that it updates the binding and the content is hidden or shown.
– AlesD
Nov 20 at 22:51
It changes if you press the Toggle button. Then you can see live that it updates the binding and the content is hidden or shown.
– AlesD
Nov 20 at 22:51
you are totally right and it also works, must have been tired when I tested this, thanks so much
– NDDTConti
Nov 21 at 8:47
you are totally right and it also works, must have been tired when I tested this, thanks so much
– NDDTConti
Nov 21 at 8:47
add a comment |
up vote
2
down vote
I also created a Stackblitz which solves them the only way I know how. Credit to AlesD for solving your first problem, all you needed to do to solve the issue is add @Input()
onto visibility which you control in the parent element.
Your issue with a context menu is less straightforward. One option that I quickly tried to show in my stackblitz using ngx-contextmenu is done using nested components. There's a nice tutorial here
As you discovered, you have to choose between using extends, or using a nested component. In my example, I use both, but it may make the most sense to just use one or the other depending:
- If your context menus are different and redundancy is not that big an issue, use extends, and build the context menu manually on each component
- if the context menus are all going to be the same, I would drop the extends entirely and use a nested component. You can access the nested component using @ViewChild to gain access to the attributes you need.
- Using both (like in my example) was used mostly for demonstrating as I don't understand the whole context of your application, but if you could abstract your cells to use a common interface or class you can pass in to the contextMenu, limiting the number of inputs, it may make sense for you.
I would love to also award you a bounty, sadly I can only do that once, thanks so much for your help
– NDDTConti
Nov 21 at 8:47
add a comment |
up vote
2
down vote
I also created a Stackblitz which solves them the only way I know how. Credit to AlesD for solving your first problem, all you needed to do to solve the issue is add @Input()
onto visibility which you control in the parent element.
Your issue with a context menu is less straightforward. One option that I quickly tried to show in my stackblitz using ngx-contextmenu is done using nested components. There's a nice tutorial here
As you discovered, you have to choose between using extends, or using a nested component. In my example, I use both, but it may make the most sense to just use one or the other depending:
- If your context menus are different and redundancy is not that big an issue, use extends, and build the context menu manually on each component
- if the context menus are all going to be the same, I would drop the extends entirely and use a nested component. You can access the nested component using @ViewChild to gain access to the attributes you need.
- Using both (like in my example) was used mostly for demonstrating as I don't understand the whole context of your application, but if you could abstract your cells to use a common interface or class you can pass in to the contextMenu, limiting the number of inputs, it may make sense for you.
I would love to also award you a bounty, sadly I can only do that once, thanks so much for your help
– NDDTConti
Nov 21 at 8:47
add a comment |
up vote
2
down vote
up vote
2
down vote
I also created a Stackblitz which solves them the only way I know how. Credit to AlesD for solving your first problem, all you needed to do to solve the issue is add @Input()
onto visibility which you control in the parent element.
Your issue with a context menu is less straightforward. One option that I quickly tried to show in my stackblitz using ngx-contextmenu is done using nested components. There's a nice tutorial here
As you discovered, you have to choose between using extends, or using a nested component. In my example, I use both, but it may make the most sense to just use one or the other depending:
- If your context menus are different and redundancy is not that big an issue, use extends, and build the context menu manually on each component
- if the context menus are all going to be the same, I would drop the extends entirely and use a nested component. You can access the nested component using @ViewChild to gain access to the attributes you need.
- Using both (like in my example) was used mostly for demonstrating as I don't understand the whole context of your application, but if you could abstract your cells to use a common interface or class you can pass in to the contextMenu, limiting the number of inputs, it may make sense for you.
I also created a Stackblitz which solves them the only way I know how. Credit to AlesD for solving your first problem, all you needed to do to solve the issue is add @Input()
onto visibility which you control in the parent element.
Your issue with a context menu is less straightforward. One option that I quickly tried to show in my stackblitz using ngx-contextmenu is done using nested components. There's a nice tutorial here
As you discovered, you have to choose between using extends, or using a nested component. In my example, I use both, but it may make the most sense to just use one or the other depending:
- If your context menus are different and redundancy is not that big an issue, use extends, and build the context menu manually on each component
- if the context menus are all going to be the same, I would drop the extends entirely and use a nested component. You can access the nested component using @ViewChild to gain access to the attributes you need.
- Using both (like in my example) was used mostly for demonstrating as I don't understand the whole context of your application, but if you could abstract your cells to use a common interface or class you can pass in to the contextMenu, limiting the number of inputs, it may make sense for you.
answered Nov 20 at 20:04
Murphy4
500513
500513
I would love to also award you a bounty, sadly I can only do that once, thanks so much for your help
– NDDTConti
Nov 21 at 8:47
add a comment |
I would love to also award you a bounty, sadly I can only do that once, thanks so much for your help
– NDDTConti
Nov 21 at 8:47
I would love to also award you a bounty, sadly I can only do that once, thanks so much for your help
– NDDTConti
Nov 21 at 8:47
I would love to also award you a bounty, sadly I can only do that once, thanks so much for your help
– NDDTConti
Nov 21 at 8:47
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53223686%2fangular6-i-want-my-inherited-component-to-have-some-propertys-of-the-parent%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Check out this blog post about Encapsulation. Maybe you'll find what you're looking for.
– ams
Nov 19 at 23:28