I have a controller method which send request to server to retrieve data. If there's some error occurs, I need to notify the user with some friendly messages. So I'm thinking I have to call certain api of UI framework
You don't necessarily need to do this. In your UI, you can have HTML (UI code) that shows the user the problem. Using ng-if
, this UI code is hidden from the user. If you controller detects a load failure, it can then set a value on the controller that will do the following
- Cause the UI code to display
- Optionally, set the display information in the UI code
<div ng-if="displayError">{{errorMsg}}</div>
Then, in your controller, something like this:
MyService.getData().then(
function(responseData) {
$scope.goodData = responseData;
},
function(failure) {
$scope.displayError = true;
$scope.errorMsg = "Failed to Retrieve Data"
}
);