0

I have a function inside my angular controller that starts when i click a certain button on my html page. What i want to do is, basically, to print an error string under the button once a certain condition verifies. I already have a working check for the condition, but how would i go to print a string once the condition is verified?

This is the my incomplete code, what should i put inside the boolean check?:

 $scope.functionName = function () {
        var  = $('#data_' + $scope.indiceSelezione).val().replace(/\//g, '');
        if (data === undefined || data === '') {
            if ($scope.response.result[$scope.index].flag === true) {

            }
            else {
              $scope.change('CONVALIDATO');
            };
2
  • What do you want to print? which variable? please rewrite your question with enough code and clarity. Commented Mar 5, 2019 at 10:56
  • I want to print a new variable that contains a string with the error. I want to put this variable inside my check directly, since i'm only gonna use it there. I want this variable to show on my html page. Commented Mar 5, 2019 at 10:57

1 Answer 1

1

You can simply assign the error message in the $scope as follows:

 $scope.controlliConvalida = function () {
        var dataRendIntegr = $('#dataRendInteg_' + $scope.indiceSelezione).val().replace(/\//g, '');
        if (dataRendIntegr === undefined || dataRendIntegr === '') {
            if ($scope.response.risultatoRicercaPrimoLivello[$scope.indiceSelezione].flagInLavorazione === true) {
              $scope.errorMessage = "Your error Message"
            }
            else {
              $scope.cambiaStatoProcesso('CONVALIDATO');
            };

In your HTML you can just print it using interpolation {{ }}

<p> {{ errorMessage }} </p>
Sign up to request clarification or add additional context in comments.

4 Comments

This works, and it already shows an error prompt under my button. Is there a way to insert the text there directly? Right now it shows the error prompt but without anything inside.
what do you mean by error prompt, can you show the image in your question?
imgur.com/a/JvxT9Pn this is the error prompt that shows right under my button. If possible, i'd like to print the string inside it.
Nevermind, i made it work. Your suggestion helped, thank you!

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.