0

Scenraio

I am pretty new to Angular and have the following issue.

I want to trigger a directive to change color and add an image on a button. I can not get the first if condition to trigger this change in my Angular Directive.

Problem

I want to make the directive take action based on the result from ng-click handler. Even though my debugger shows that directive is being called, I am not getting the first if condition to enter.

Questions

1) What do I need to do to get this to work?

2) Do I need to consider if ng-click is not called before the directive is handled?

HTML

<button class="email-reset-btn"  type="button" ng-click="resetEmailLink();" emailReset="changeBtn();" name="button">Email Reset Link</button>

Scope Level Function

var emailResetValidation = function () {
  if($('#email').val().trim() == "")
  {
    $(".email-reset-btn").removeClass("email-active-green");
  }
}

Directive

.directive('emailReset', [function(){
      return {
        link: function(scope, elem, attrs) {
          elem.bind("click", function(){
            if(!elem.hasClass('email-active-green')) {  <--- Here is where I want the debugger to enter to change the button's HTML
               elem.html("<div class='email-sent-placeholder'><img width='15px' src='./resources/icons/[email protected]'/></div>&nbsp;<div class='email-reset-button-text'>Link Sent</div>");
            }
            else {
               elem.html("Email Reset Link");
            }
          })
        }
      });
3
  • Could you please share the html of #email ? Commented Sep 29, 2016 at 5:56
  • #email is just a text input whose id is "email" Commented Sep 29, 2016 at 5:58
  • I don't get the logic around when each of the buttons should show. And you are mixing angularjs with jQuery for the most basic thing as checking scope models. I've added a plunkr, which is a fork from QI.soa plunker, were you can see little small changes which makes angularjs awesome plnkr.co/edit/2fq3ndcN0XbOtiBDV4Kx?p=preview Commented Sep 29, 2016 at 6:33

1 Answer 1

0

if you want to use the emailReset directive.you should set the email-reset in your HTML like this

 <button class="email-reset-btn"  type="button" ng-click="resetEmailLink();" email-reset="changeBtn();" name="button">Email Reset Link</button> 

and I can't understand what the emailReset = "changeBtn()" means?

try to see this plunker

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

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.