Solved

angular adding row after adding value from jquery

Posted on 2015-01-14
4
150 Views
Last Modified: 2015-01-15
http://plnkr.co/edit/QZymHM?p=preview

Ok the problem I am having is I can type inside the text box the click add and it add the value to the table row. The problem is I am using jquery to add the value but angular directive does not detect this.
the class shows (( ng-valid ng-dirty ng-touched )) but if I enter some value I see (( ng-valid ng-dirty ng-touched )) how can i tell angular there is a value there??
0
Comment
Question by:sevensnake77
  • 2
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
ambience earned 500 total points
ID: 40550887
It is really not a good idea to use jQuery to mess with data when using angularJS. Let aJS manage the bindings and everything and use jQ only for UI effects. In the rare cases when you really must, you can access the Controllers scope from outside.

Also, it would increase encapsulation (in such cases) if you rather expose a method like setPerson(firstN, lastN) so that you don't have to access $scope.firstname etc.

    var scope = angular.element($("#cotroller")).scope();
    scope.$apply(function(){
        scope.firstname = 'john';
        scope.lastname = 'Doe';
    });

Open in new window


Check plunkr: http://plnkr.co/edit/UByO9PFpxYC9jMG4VFI8?p=preview
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 40551182
your example does not seem to work?
0
 
LVL 22

Expert Comment

by:ambience
ID: 40551197
This happened to me twice - plunkr not getting saved. Check again.

I just added id="controller" to the DIV with ng-controller attrib.
0
 
LVL 9

Author Closing Comment

by:sevensnake77
ID: 40551235
thanks for the wisdom
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now