5

Hi My project works on Djnago and AngularJS. I want include bootstrap alerts once the user submit. If it is successful show alert-success etc. How can I do this? The following is my angularJS code:

$scope.submit =function(){
    data = {};
    angular.extend(data, $scope.final_data);
    angular.extend(data, { xxx: $scope.final_data.xxx });
    $http.post('{% url 'submission' %}', data).success(
        function(data){
            $scope.get_info();
            alert('DONE!')
        }).error(function(){
            alert('not submitted');
    })
};

Both the alert is working, I want to replace that with bootstrap alerts. How can I do that? Thanks in advance.

4
  • I search and get this custom directive . github.com/marcorinck/angular-growl . you can use this. Commented Oct 26, 2015 at 2:57
  • Hi Jigs, Am confused how can I use this in this scenario Commented Oct 26, 2015 at 3:43
  • I dont understand why there is a list after the controller Commented Oct 26, 2015 at 3:47
  • Sorry i haven't used that module . you can use bootstrap alert . well see my answer for sample example . Commented Oct 26, 2015 at 4:59

4 Answers 4

5

Well, you can show/hide alert using ng-show/ng-hide according to error status . I have created a sample plunker.

<alert ng-show='alertType' type="{{alertType}}" close='removeAlert()'>{{alertType}} Alert</alert>
  <select ng-model="alertType">
    <option>danger</option>
    <option>success</option>
    <option>warning</option>
  </select>

This may help you.

Sign up to request clarification or add additional context in comments.

1 Comment

@Hema CDN wasn't working. Thanks for reminding. It is working now but it's kind of old style.
3

Use AngularUI (bootstrap directives for Angular)

https://angular-ui.github.io/bootstrap/#/alert

1 Comment

Hi mcpDESIGNS, I know this. But how can I implement this to my angularJS part?
0

Please look into this package and add your opinions https://www.npmjs.com/package/lg-custom-alert

<button lg-alert="[scope-function]" lg-size="[size of the modal]" lg-type="[type]" lg-message="[message need to be displayed in the alert">
    Alert 
</button>

Comments

0

Here is the workaround I have used

view file:

<div class="alert alert-{{ResponseModel.ResponseType}}" alert-dismissible ng-show="ResponseModel.ResponseAlert">
<a href="#" class="close" ng-click="ResponseModel.ResponseAlert = false" aria-label="close">&times;</a>
<strong> {{ResponseModel.ResponseMessage}} </strong>
</div>

This helps to close the alert message box when required and also appear again when displaying the alert message. Here ResponseModel.ResponseType will be the type of alert that could info, danger, success, etc., ResponseModel.ResponseAlert will be used to show hide the alert message and ResponseModel.ResponseMessage will contains the message you want to display. You can call the alert message whenever required like described below:

Controller File:

$scope.ResponseModel = {};
$scope.ResponseModel.ResponseAlert = true;
$scope.ResponseModel.ResponseType = "danger";
$scope.ResponseModel.ResponseMessage = "Message to be displayed!!"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.