ng-dblclick not run to find the controller's function when using ng-repeat and data binding

571 views
Skip to first unread message

Amit Kumar

unread,
Dec 19, 2012, 8:39:21 PM12/19/12
to ang...@googlegroups.com
I am facing this issue when using ng-repeat and ng-dblclick

It works when I use a plain String, the ng-dblclick function is able to find the controller's function and execute it. The code below works and the modalShown is set correctly.

<tr ng-repeat="product in searchResults"  ng-dblclick="editProductCopy('123456-010','HO2013');">
<td><input type="checkbox" value="2" checked></td>
<td>Spring 2013</td>
<td>{{product._id}}</td>
                      
</tr>

However it doesn't work in this scenario when I use model binding within a ng-repeat. I tried invoking it with $parent. editProductCopy but could not get it to work

<tr ng-repeat="product in searchResults"  ng-dblclick="editProductCopy('{{product._id}}','HO2013');">
<td><input type="checkbox" value="2" checked></td>
<td>Spring 2013</td>
<td>{{product._id}}</td>
                      
</tr>


The controller code is : 


function ProductSearchCtrl ( $scope, $routeParams,ProductSearch)  {
        $scope.modalShown  = false;
        $scope.editProduct = null;
        $scope.searchResults = [];
        $scope.clickCount = 0;
        $scope.searchProducts = function ( season,division,category) {
            $scope.searchResults =  ProductSearch.query({'season':season,'division':division,'category':category});
        };
        $scope.editProductCopy = function ( productCode, season ) {
            $scope.modalShown  =  ! ($scope.modalShown );
            $scope.clickCount = $scope.clickCount + 1 ;
            $scope.editProduct =  { productCode:productCode, season:season, styleName : 'Test Style Name'}
        };
}

I am sure it is due to the new scope created by the ng-repeat tag,but I am not sure how to invoke the call to the controller's function.

Any help is highly appreciated, 


Peter Bacon Darwin

unread,
Dec 20, 2012, 1:50:55 AM12/20/12
to ang...@googlegroups.com

Hi Amit
Rather than dump code into an email can you provide a working example?

Pete
...from my mobile.

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
 
 

Amit Kumar

unread,
Dec 20, 2012, 2:05:02 AM12/20/12
to ang...@googlegroups.com
Thanks for the reply. I will do that as soon as I can.

Amit Kumar

unread,
Dec 20, 2012, 1:13:55 PM12/20/12
to ang...@googlegroups.com
Here is the Plunker. I can replicate this issue on the Plunker - http://plnkr.co/edit/ivF8EO?p=preview

Basically , on line # 27, substituting the string '1234567' with the  binding {{  product._id }} causes the double click event to stop firing ( Maybe it is not finding the parent's function ) 

Pawel Kozlowski

unread,
Dec 20, 2012, 1:20:38 PM12/20/12
to ang...@googlegroups.com
Hi!

On Thu, Dec 20, 2012 at 7:13 PM, Amit Kumar <amits...@gmail.com> wrote:
> Basically , on line # 27, substituting the string '1234567' with the
> binding {{ product._id }} causes the double click event to stop firing (
> Maybe it is not finding the parent's function )

It should read:
<tr ng-repeat="product in searchResults"
ng-dblclick="editProductCopy(product._id,'HO2012')">

You had a bit of a mess in the plunk (jasmine, mocks etc. were
included etc.), cleaned it up a bit:
http://plnkr.co/edit/PRqbah?p=preview

Cheers,
Pawel
--
Question? Send a fiddle
(http://jsfiddle.net/pkozlowski_opensource/Q2NpJ/) or a plunk
(http://plnkr.co/)
Need help with jsFiddle? Check this:
http://pkozlowskios.wordpress.com/2012/08/12/using-jsfiddle-with-angularjs/

Looking for UI widget library for AngularJS? Here you go:
http://angular-ui.github.com/

Amit Kumar

unread,
Dec 20, 2012, 2:48:15 PM12/20/12
to ang...@googlegroups.com
Thanks! I thought I fixed those.  Sorry for the errors,  I am still learning Plunkr. 
Reply all
Reply to author
Forward
0 new messages