Solved

angular adding row after adding value from jquery

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

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…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
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…

815 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

10 Experts available now in Live!

Get 1:1 Help Now