4
這是可以配置的嗎?Angular.js表達式拋出異常
從here,表情是寬容,但我想知道我的錯誤是什麼。
Forgiving:在JavaScript中,試圖評估未定義的屬性會生成ReferenceError或TypeError。在Angular中,表達式評估原諒未定義且爲空。
這是可以配置的嗎?Angular.js表達式拋出異常
從here,表情是寬容,但我想知道我的錯誤是什麼。
Forgiving:在JavaScript中,試圖評估未定義的屬性會生成ReferenceError或TypeError。在Angular中,表達式評估原諒未定義且爲空。
其實有,
在角中,$插值服務負責與綁定表達式的工作,因爲這項服務是至赦的,你看不到任何錯誤。但是,您可以爲它創建包裝,以便在可能出現錯誤結果時通知您。下面
代碼爲http://odetocode.com/See this blog post
app.config(function($provide){
$provide.decorator("$interpolate", function($delegate){
var interpolateWrap = function(){
var interpolationFn = $delegate.apply(this, arguments);
if(interpolationFn) {
return interpolationFnWrap(interpolationFn, arguments);
}
};
var interpolationFnWrap = function(interpolationFn, interpolationArgs){
return function(){
var result = interpolationFn.apply(this, arguments);
var log = result ? console.log : console.warn;
log.call(console, "interpolation of " + interpolationArgs[0].trim(),
":", result.trim());
return result;
};
};
angular.extend(interpolateWrap, $delegate);
return interpolateWrap;
});
});
你可能已經想通了這一點現在,但恐怕也沒有辦法來配置。 – gkalpak