Angular.js: ng-click is funny behavior in v1.4.2

Created on 15 Jul 2015  路  7Comments  路  Source: angular/angular.js

When I click on tag with ng-click,

<button class="btn btn-warning" ng-click="updateGroup()" ng-disabled="updateGroup.$invalid">update</button>

get this error.

TypeError: v2.updateGroup is not a function
    at fn (eval at <anonymous> 

Where "v2" come from?

$parse more info

Most helpful comment

v2 is coming from the parser (it is basically your current scope).
This error happens because you are trying to call scope.updateGroup(), but scope.updateGroup is not a function (it is defined, but it is not a function).

Since you seem to be using updateGroup.$invalid, I assume you might have a <form> named updateGroup, in which case it would overwrite a scope.updateGroup function already existing on the scope.

Bottom line, either change your function name or change your form name, so the latter does not overwrite the former.

All 7 comments

@pyonnuka please provide a minimal (but complete) reproduce scenario, see bug submission guidelines: https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md#submitting-an-issue

v2 is coming from the parser (it is basically your current scope).
This error happens because you are trying to call scope.updateGroup(), but scope.updateGroup is not a function (it is defined, but it is not a function).

Since you seem to be using updateGroup.$invalid, I assume you might have a <form> named updateGroup, in which case it would overwrite a scope.updateGroup function already existing on the scope.

Bottom line, either change your function name or change your form name, so the latter does not overwrite the former.

BTW, this is not specific to v1.4.2 (an error is thrown as back as 1.3.1).
In fact, it used to throw TypeError: Cannot read property '0' of null on v1.3.x, so I guess this is a nice improvement (the error makes much more sense now).

As @gkalpak mention, the forgiving nature of angular expressions never included function calls on things that are defined but are not callable.

@gkalpak I love you right now, it might be lust.

just to recap, the function has the same name as another variable and is conflicting in $scope

@gkalpak Thanks so much

This error usually happens when you're trying to call a scope variable as a function when it's not actually a function, i.e.

// html inside your controller element
<button ng-click="sayHello()">Hello</button>
// js in your controller
$scope.sayHello= 'hello';
// where it SHOULD be
$scope.sayHello = () => 'hello';

It should be a simple fix, just track down where you're reassigning or misdeclaring $scope.updateGroup

edit: also, I didn't realize this issue was closed :cry:

Was this page helpful?
0 / 5 - 0 ratings