Ad

Use Angularjs Ng-blur With A Call To Javascript

- 1 answer

I use AngularJs 1.3.4

$scope.change = function (id) {
    console.log("test onChange... " + id);
};

<input ng-change="change({{question.id}})"is OK

but <input ng-blur="change({{question.id}})" have a syntaxe error

Error: [$parse:syntax] Syntax Error: Token '{' invalid key at column 9 of the expression [change({{question.id}})] starting at [{question.id}})].
http://errors.angularjs.org/1.3.4/$parse/syntax?p0=%7B&p1=invalid%20key&p2=9&p3=change(%7B%7Bquestion.id%7D%7D)&p4=%7Bquestion.id%7D%7D)
    at http://localhost:8080/bower_components/angular/angular.js:63:12
Ad

Answer

You shouldn't be using "{{var}}" in the call at all, angular automatically interpolates values in the scope. All you need to do is:

<input ng-blur="change(question.id)" />

My guess is ng-blur and ng-change handle them differently because it's against standard.

Ad
source: stackoverflow.com
Ad