AngularJS使用的DataService breezejs它没有解决的承诺 [英] AngularJS dataservice using breezejs it not resolving the promise
问题描述
我想建立一个数据服务正在使用breezeJS我的角度应用。我解决我的诺言之后,我不能让我的控制器以文件的。那么。我在我的数据业务通过微风获取数据从我的数据库了。我可以传回微风希望,但是我希望能够使用$ q.all知道什么时候我所有的数据已被找到。
I'm trying to setup a data service in my Angular application that is using breezeJS. After I resolve my promise I can't get the .then to file in my controller. I am getting data back from my database via breeze in my data service. I could just pass back the breeze promise but I want to be able to use $q.all to know when all my data has been found.
在我controller`
In my controller`
ProApp.controller('caseInfoController',
功能caseInfoController($范围,$日志$超时,caseDataService){
ProApp.controller('caseInfoController', function caseInfoController($scope, $log, $timeout, caseDataService) {
/***initialize data ***/
// initializeApp();
ATPinitializeApp();
function ATPinitializeApp() {
$scope.MyStateList= caseDataService.getAllStates()
.then(function assignStates(data) {
$log.info("THIS THEN WILL NOT FIRE");
});
}
`
以上,然后,将不会触发时从数据服务的承诺得到满足。
The above then will not fire when the promise from the data service is fulfilled.
ProApp.factory('caseDataService', function ($log, $q)
{
breeze.config.initializeAdapterInstance("modelLibrary", "backingStore", true);
var servicename = "http://localhost:60882/breeze/SPLBreeze";
var manager = new breeze.EntityManager(servicename);
var caseDataService =
{
getAllStates: getAllStates,
};
return caseDataService;
/*** implementation details ***/
function getAllStates()
{
var myStatePromise = $q.defer();
var query = breeze.EntityQuery
.from("state");
manager.executeQuery(query)
.then(function (data) {
$timeout(function () { myStatePromise.resolve(data); }, 200);;
});
return myStatePromise.promise;
};
任何帮助将大大AP preciated。我敢肯定不是100%,如果我有$ Q承诺正确设置。最后,我想用一个$ q.all,以确定各种承诺的阵列已经被解决,这样我就可以更新信息给用户。我一直在读,我需要使用超时来获得角度认识到,改变在未来的事件循环发生。
Any help would be greatly appreciated. I'm not 100% sure if I have the $q promises set up correctly. Eventually I would like to use a $q.all to determine when an array of various promises have been resolved to so I can update a message to the user. I've been reading that I need to use a timeout to get angular to realize that a change has happened in the next event loop.
推荐答案
您正在盯着一个角度$ Q错误的桶。你可以阅读一下在这里,如果你想。
You're staring down the barrel of an Angular $q bug. You can read about it here if you wish.
这将不利于远远不如按照<一的建议href=\"http://stackoverflow.com/questions/17724519/resolving-breeze-query-q-promise-with-route-resolve-stops-page/17733185#17733185\">my回答这个StackOverflow的相关问题 我在其中显示和说明适配器从Q.js承诺到$ Q承诺就搞定了。
That won't help nearly as much as following the advice in my answer to this related StackOverflow question in which I show and describe an adapter to get from Q.js promise to a $q promise.
这篇关于AngularJS使用的DataService breezejs它没有解决的承诺的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!