Solved

angular adding row after adding value from jquery

Posted on 2015-01-14
4
158 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

839 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