1

I'm new in angularjs write this code:

<ng-input theme='fumi' id='txtEmail' label='پست الکترونیک' icon='icon icon--fumi mdi mdi-select-all' style="font-size:medium;width:40%;"></ng-input>


and try to read that value with jquery with this way:

var EmailPattern = $('#txtEmail').val();
                alert(EmailPattern);


but alert show me null value,how can i solve that problem?thanks all.

6
  • ng-input? You aure that exists? Commented Nov 12, 2016 at 12:19
  • 2
    Can you place a code for your ng-input directive? Commented Nov 12, 2016 at 12:22
  • 2
    Why would you ever need to do this using jQuery? Use ng-model on form controls. Note that <ng-input> can't have a value, it's not a form control. Show all relevant code Commented Nov 12, 2016 at 12:26
  • @charlietfl how can i use that?please post code solution Commented Nov 12, 2016 at 12:45
  • docs.angularjs.org/guide/forms Commented Nov 12, 2016 at 12:50

1 Answer 1

1

As stated in the comments you should avoid using jquery for getting an input value, by doing so you are breaking all rules of AngularJS. There is no need for jquery since you can use the ng-model directive.

HTML

<ng-input theme='fumi' id='txtEmail' ng-model='text_email' label='پست الکترونیک' icon='icon icon--fumi mdi mdi-select-all' style="font-size:medium;width:40%;"></ng-input>

In your controller:

alert($scope.text_email);

Angular will get the scope variable updated whenever you change the input value. Simple like that.

Also keep in mind that Angular binding is two-way. This means that you can change the scope variable and see the change reflecting on the HTML

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

1 Comment

Please Wait for test Your Solution.Thanks for answer

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.