我们目前正试图让微风和角度协同工作...我们试图避免的一件事是在每次远程过程调用后必须手动调用$ scope.apply()...我正在尝试写一个“ ajax“将使用angular的$ http服务的适配器实例...但问题是angular的http服务没有公开xhr对象...我想,不确定这是一个问题因为我相信breeze期望这个对象存在,甚至将它暴露给客户端......真正唯一想要实现的就是能够调用$ scope.apply()AFTER breeze从服务器返回并完成所有工作,包括调用客户端回调..我想这样做而不需要更改微风源代码,我知道微风是非常可扩展的...但它也是一个非常大的库,我很难找到截取点在哪里...有没有人有任何建议???谢谢
答案 0 :(得分:1)
您已正确识别问题。现在Breeze确实期望XHR和角度不会返回一个。我们有一个功能请求应该在接下来的几个版本之一中允许你将angular的http服务包装为'breeze'ajax适配器。
现在虽然:( 其余部分是推测性的和未经测试的,但总体思路应该有效),您最好的选择可能是创建现有“ajax”适配器的装饰版本。就像是。
var origAjaxCtor = breeze.config.getAdapter("ajax");
var newAjaxCtor = function () {
this.name = "newAjax";
this._origAjaxCtor = new origAjaxCtor();
}
newAjaxCtor.prototype = new oldAjaxCtor(); // to delegate all other methods
newAjaxCtor.prototype.ajax = function (settings) {
settings.success = function((data, textStatus, XHR) {
// call the original success code
settings.success(data, textStatus, XHR);
// followed by your custom scope code.
// ...do your scope apply here...
});
// perform the actual ajax call - this will call your custom success method from above.
this._origAjaxCtor.ajax(settings);
}
// register the new adapter
breeze.config.registerAdapter("ajax", newAjaxCtor);
// make this adapter the default
breeze.config.initializeAdapterInstance("ajax", "newAjax", true);
答案 1 :(得分:0)
从Breeze 1.4.4开始,我们现在支持使用$ http的角度ajax适配器。有关更多详细信息,请参阅1.4.4发行说明。
对于您的特定问题,如果您使用angular ajax适配器的setHttp方法,您可以让Breeze在内部使用您的$ http实例。