feat(Modal): available to use 'BsModalRef.setClass' in modal component ngOnInit lifecycle.
🐛Bug description or feature request:
Feature Request 😆
Explanation
Now, we have to use 'setClass' method like this.
this.bsModalService.show(CartSuccessModalCompoennt, {
'class': 'cart-modal'
});
or we can use this way.
const bsModalRef = this.bsModalService.show(CartSuccessModalCompoennt);
bsModalRef.setClass('cart-modal');
In this way, we have to call 'bsModalRef.setClass' or set options {'class': 'cart-modal'} in everywhere we call .show method.
I suggest 🙋♂️ that we should make bsModalRef.setClass method available to call in modal component lifecycle.
This is the example what i suggest.
@Component({
selector: 'cart-success-modal',
templateUrl: './cart-success-modal.component.html',
styleUrls: ['./cart-success-modal.component.scss']
})
export class CartSuccessModalComponent {
constructor(public bsModalRef: BsModalRef) {
}
ngOnInit() {
this.bsModalRef.setClass('modal-sm');
}
}
In 5.1.1 version, above example not works because at that moment (ngOnInit timing), this.bsModalRef.setClass is just Function (native code).
So, i change bsModalService._showModal implementation to assign setClass function before starting ngOnInit lifecycle.
I make PR request for this feature. Please see the changes and give me a feedback.
Versions of ngx-bootstrap, Angular, and Bootstrap:
ngx-bootstrap: 5.1.1
Angular: 7.x, 8.x
Bootstrap: 3.x
Build system: Angular CLI, System.js, webpack, starter seed:
This would be amazing and I'm surprised it's not already a feature. The documentation makes it seem like this is possible with a component modal however whenever BsModalRef.class(....) is used in the component, this error appears:
ERROR SyntaxError: Unexpected identifier
at BsModalRef.Function (<anonymous>)
This would be extremely helpful as otherwise each code that tries to create the modal component would have to know implementation details like css classes, thus way too much tight coupling.