How to get cart discount amount in minicart in Magento 2

Here we will learn about How to get cart discount amount in minicart in Magento 2.

We have to create a new module if you already not created, after that follow the steps that describe in the post.

#1 : We need to register the Plugin in magento 2.

add the following code in “etc/frontend/di.xml” of your module

#2 : Add the following code in your plugin file.

Namespace\Modulename\Plugin\CustomerData\Cart.php

#3 : Now you need to run the dependancy Setup in your console or terminal command.

php bin/magento setup:di:compile

#4: Flush the cache in your console or terminal command.

php bin/magento cache:clean && bin/magento cache:flush