magento2 – How to display child products out of stock of a configurable product in detail and on the magento 2 product display page?

I'm trying to show children's products out of stock for configurable product in detail and in view of the product. I have changed the catalog inventory settings to view products out of stock, even if it does not show up.
I've tried the code below but does not work.

data.php

imageHelper = $ imageHelper;
$ this-> stockRegistry = $ stockRegistry;
$ this -> _ productloader = $ _productloader;
$ this -> _ storeManager = $ storeManager;
parent :: __ construct ($ imageHelper);
}


public function getOptions ($ currentProduct, $ allowedProducts)
{
$ objectManager =  Magento  Framework  App  ObjectManager :: getInstance ();
// $ stockRegistry = $ objectManager-> get (Magento  CatalogInventory  Api  StockRegistryInterface & # 39;);
$ options = [];
foreach ($ allowedProducts as $ product) {
$ productId = $ product-> getId ();
$ product = $ objectManager-> get (Magento  Catalog  Model  Product) -> load ($ productId);
$ stockitem = $ this-> stockRegistry-> getStockItem ($ product-> getId (), $ product-> getStore () -> getWebsiteId ());
if ($ stockitem-> getQty () == 0) continues;
$ images = $ this-> getGalleryImages ($ product);
if ($ images) {
foreach ($ images as $ image) {
$ options['images'][$productId][]    =
                        [
                            'thumb' => $image->getData('small_image_url'),
                            'img' => $image->getData('medium_image_url'),
                            'full' => $image->getData('large_image_url'),
                            'caption' => $image->getLabel(),
                            'position' => $image->getPosition(),
                            'isMain' => $image->getFile() == $product->getImage(),
                        ];
}
}
foreach ($ this-> getAllowAttributes ($ currentProduct) as $ attribute) {
$ productAttribute = $ attribute-> getProductAttribute ();
$ productAttributeId = $ productAttribute-> getId ();
$ attributeValue = $ product-> getData ($ productAttribute-> getAttributeCode ());
$ options[$productAttributeId][$attributeValue][]    = $ productId;
$ options['index'][$productId][$productAttributeId]    = $ attributeValue;
}
}
returns $ options;
}


}

di.xml