How to display message in Angularjs?

Asked

Viewed 1,362 times

1

I am working with angular and need to add a message on the screen when being prompted the check code button. An error or success message.

Angular controller

angular.module().controller(){ 
        vm.validarProtocolo = function(){          
            //exibir mensagem na tela
        };
}

Html Code

<input type="text" name="protocolo" ng-model="brSafe.protocolo">
<button ng-click="validarProtocolo()">Validar Protocolo</button>
  • You need to display the message, but, missed as you wish, have some idea a simple alert javascript solves?

  • I’ve used Alert. It didn’t work.. I need the message to be a text message next to the red spam boot

  • if you need at which moment, by clicking the button?

  • that’s right. When you click on the button this function is called: validate

  • 1

    Detail a little more your need, Alex. "Need to add a message" - Add where? What type? What criteria? The way his question was formulated, Thiago’s answer is fully correct.

  • Thiago answered my question. Something simple and direct!

Show 1 more comment

1 answer

4


In a simple way, making a function display a message:

var app = angular.module('root', []);
app.controller('myCtrl', function($scope) {
    $scope.message = "";
    
    $scope.validarProtocolo = function(){     
        $scope.message = "TESTE";
    };
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="root" ng-controller="myCtrl">
  <p ng-if="message">{{message}}</p>
  <button ng-click="validarProtocolo()">TESTE</button>
</div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.