How to extend / inherit components?

后端 未结 12 820
萌比男神i
萌比男神i 2020-12-02 04:11

I would like to create extensions for some components already deployed in Angular 2, without having to rewrite them almost completely, as the base component could undergo ch

12条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-02 05:09

    just use inheritance,Extend parent class in child class and declare constructor with parent class parameter and this parameter use in super().
    
    1.parent class
    @Component({
        selector: 'teams-players-box',
        templateUrl: '/maxweb/app/app/teams-players-box.component.html'
    })
    export class TeamsPlayersBoxComponent {
        public _userProfile:UserProfile;
        public _user_img:any;
        public _box_class:string="about-team teams-blockbox";
        public fullname:string;
        public _index:any;
        public _isView:string;
        indexnumber:number;
        constructor(
            public _userProfilesSvc: UserProfiles,
            public _router:Router,
        ){}
    2.child class
    @Component({
    
        selector: '[teams-players-eligibility]',
        templateUrl: '/maxweb/app/app/teams-players-eligibility.component.html'
    })
    export class TeamsPlayersEligibilityComponent extends TeamsPlayersBoxComponent{
    
        constructor (public _userProfilesSvc: UserProfiles,
                public _router:Router) {
                super(_userProfilesSvc,_router);
            }
    }
    

提交回复
热议问题