我想翻译我的应用程序,而不对 HTML 进行任何更改。
我想创建一个拦截器,在将每个元素附加到 DOM 之前接收它。然后我可以获取文本节点并翻译它们。
类似的事情:
app.config(function (DOMIntercepter){
DOMINtercepter.onElementAdded(){
TranslateElementContent()
})
})
例如,当 Angular 指令读取 HTML 模板文件时,我想在指令获取模板之前翻译该文件。
你有更好的主意吗?
最佳答案
您可以使用 $http 拦截器:
app.factory('htmlInterceptor', function() {
return {
response: function(res) {
if (res.headers('content-type').match(/html/)) {
res.data = manipulateHtml(res.data);
}
return res;
}
}
});
app.config(function($httpProvider) {
$httpProvider.interceptors.push('htmlInterceptor');
});
关于javascript - 在 AngularJS 中将每个 HTML 元素附加到 DOM 之前对其进行预处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35251765/