2016-01-24 55 views
2

我用AngularJs通話1.3.4使用angularjs NG-模糊帶的JavaScript

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

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

<input ng-blur="change({{question.id}})"syntaxe錯誤

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 

回答

4

你根本不應該在調用中使用「{{var}}」,角度會自動插入va在範圍內引起注意。所有你需要做的是:

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

我的猜測是ng-blur和ng-change處理它們的方式不同,因爲它違背了標準。

0

區別在於參數解析的時間。在編譯時試圖解析{{question.id}}。這是角度$ parse的不正確語法。

ngChange解析{{question.id}}事件發生時,值已經被插入,這就是爲什麼你不叫ng-change功能與{{question.id}},在佔位符的位置精確值