behi behi
behi behi

Reputation: 137

Why i can not read angular js input value with jquery?

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.

Upvotes: 1

Views: 138

Answers (1)

Sarantis Tofas
Sarantis Tofas

Reputation: 5167

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

Upvotes: 1

Related Questions