angular 在 YUI 缩小时捕获关键字错误
angular catch keyword error on YUI minification
我在 ajax 调用中使用了 then 和 catch:
try {
ServiceData.getProductDetails(product).then(function(data) {
$scope.productDetails = data;
})
**Line 445** .catch(function(fallback) {
$scope.buildProductDetails(product);
});
} catch (err) {
$scope.buildProductDetails(product);
}
};
}
]);
在缩小时我收到无效 catch 块的错误:
[ERROR] 445:27:missing name after . operator
[ERROR] 446:32:syntax error
[ERROR] 447:22:'try' without 'catch' or 'finally'
[ERROR] 448:20:missing ; before statement
[ERROR] 449:24:syntax error
[ERROR] 451:9:missing ] after element list
[ERROR] 452:5:syntax error
[ERROR] 453:2:syntax error
如何告诉 YUI .catch 是 angular catch 而不是传统的 try catch。
请帮忙
AngularJS 的 $q
中的 .catch
方法(被 $http
使用)与 catch
的语句不同14=] 块。您使用的 try {
是错误的,您不应该使用它。
为了让事情更清楚:
"catch(errorCallback)
– shorthand promise.then(null, errorCallback)
"。这是调用 reject inside the promise. (https://docs.angularjs.org/api/ng/service/$q#the-promise-api)
时的函数 callend
try ... catch
语句是内置的 JavaScript 机制。当您在 try
块中使用 throw 'some exception'
时,会执行 catch
块中的代码。
reject
的 AngularJS 文档非常清楚:"When comparing deferreds/promises to the familiar behavior of try/catch/throw, think of reject as the throw keyword in JavaScript." 不过,为了安全起见,我会添加“虽然概念上相似,但不要别把它们搞混了!" :)
我在 ajax 调用中使用了 then 和 catch:
try {
ServiceData.getProductDetails(product).then(function(data) {
$scope.productDetails = data;
})
**Line 445** .catch(function(fallback) {
$scope.buildProductDetails(product);
});
} catch (err) {
$scope.buildProductDetails(product);
}
};
}
]);
在缩小时我收到无效 catch 块的错误:
[ERROR] 445:27:missing name after . operator
[ERROR] 446:32:syntax error
[ERROR] 447:22:'try' without 'catch' or 'finally'
[ERROR] 448:20:missing ; before statement
[ERROR] 449:24:syntax error
[ERROR] 451:9:missing ] after element list
[ERROR] 452:5:syntax error
[ERROR] 453:2:syntax error
如何告诉 YUI .catch 是 angular catch 而不是传统的 try catch。 请帮忙
AngularJS 的 $q
中的 .catch
方法(被 $http
使用)与 catch
的语句不同14=] 块。您使用的 try {
是错误的,您不应该使用它。
为了让事情更清楚:
"catch(errorCallback)
– shorthand promise.then(null, errorCallback)
"。这是调用 reject inside the promise. (https://docs.angularjs.org/api/ng/service/$q#the-promise-api)
try ... catch
语句是内置的 JavaScript 机制。当您在 try
块中使用 throw 'some exception'
时,会执行 catch
块中的代码。
reject
的 AngularJS 文档非常清楚:"When comparing deferreds/promises to the familiar behavior of try/catch/throw, think of reject as the throw keyword in JavaScript." 不过,为了安全起见,我会添加“虽然概念上相似,但不要别把它们搞混了!" :)