Discussion on: Angular: How to easily display loading indicators

johncarroll profile image
John Carroll Author

It is possible, unintentionally, swIsLoading to have a key and the submit function to add a different key.

Is this an actual problem you are running into? This hasn't been a problem for me.

Another thing, besides your strategy being very good, there is still an effort to define the same key in swIsLoading and in the submit function.

No, defining the key twice is a feature, it's not simply an implementation detail. It's enforcing a separation of concerns. You're treating the submit() function like it's tied to the view when it's not. submit() can be called elsewhere and it still will trigger the "create-user" loading state. Similarly, the view's "create-user" loading state can also be triggered by other means (not just the submit() function).

Put another way, the button's loading indicator is triggered by the "create-user" loading state. It is not triggered by the submit() function (though, in this case, the submit() function happens to trigger the "create-user" loading state). Tying the button's loading state specifically to the submit() function would be undesirable.

Regardless, it sounds like you might be interested in the Angular Promise Buttons library, which has a less abstract button loading indicator solution that might appeal to you.

mhagnumdw profile image