I'll tell you an idea, but I won't explain it in detail, because I don't like to reach out to others... I'll give you the plan, at least use your brain to think about it.
First of all, the following code does not use ui-bootstrap's $modal, but ng-strap's $modal. The reason is that I think the code quality of the latter is better than the former, but the latter is relatively new and the API is not as complete as the former. Therefore, you need to have relatively strong hands-on skills, but this has nothing to do with the expansion of $modal service that I will talk about next.
Secondly, you must consider these issues before extending a public $modal service:
What can be reused? Which ones need to be (possibly) newly specified each time? (templates, parameters, methods, etc.)
What is the expected calling method? What does the return result look like?
How high are the scalability and flexibility requirements?
There is no clear answer to these questions at the beginning, but you need to simulate an answer in your mind, because it will determine how to write your service.
The first step is to prepare the default parameters; these are the parameters provided by the original $modal. First set an initial state (according to your own needs)
Step 2: Write the attribute extension code of the new service; so that the new service can have the same attribute extension capabilities as the original $modal
Then there is the definition of ConfirmModal, and the final return is $promise, so that the caller can expand his or her business logic; I added some comments at the key points, and the rest can be understood by yourself:
I'll tell you an idea, but I won't explain it in detail, because I don't like to reach out to others... I'll give you the plan, at least use your brain to think about it.
First of all, the following code does not use ui-bootstrap's $modal, but ng-strap's $modal. The reason is that I think the code quality of the latter is better than the former, but the latter is relatively new and the API is not as complete as the former. Therefore, you need to have relatively strong hands-on skills, but this has nothing to do with the expansion of $modal service that I will talk about next.
Secondly, you must consider these issues before extending a public $modal service:
There is no clear answer to these questions at the beginning, but you need to simulate an answer in your mind, because it will determine how to write your service.
The first step is to prepare the default parameters; these are the parameters provided by the original $modal. First set an initial state (according to your own needs)
Step 2: Write the attribute extension code of the new service; so that the new service can have the same attribute extension capabilities as the original $modal
Then there is the definition of
ConfirmModal
, and the final return is $promise, so that the caller can expand his or her business logic; I added some comments at the key points, and the rest can be understood by yourself:Call example:
For templates, just refer to the original $modal and rewrite it yourself. The code is available on github, that’s it.