gpt4 book ai didi

AngularJs console.log "$q is not defined"

转载 作者:行者123 更新时间:2023-12-02 21:56:47 27 4
gpt4 key购买 nike

我在控制台中收到此错误 $q 未定义。当我做了一些研究时,我发现诸如 .q 库之类的东西已被弃用 http://www.breezejs.com/documentation/breeze-labs/breezeangularqjs

如果是这样,那么 Promise 的整个概念也被弃用了,

最佳答案

Promise 并未被弃用。事实上,它们最近获得了相当大的发展势头,并包含在下一版本的 JavaScript 中。

让我们看看他们怎么说:

This breeze.angular.q library has been deprecated. It is superseded by the Breeze Angular Service which more cleanly configures breeze for Angular development.

The Breeze Angular Service tells Breeze to use Angular's $q for promises and to use Angular's $http for ajax calls.

他们所说的是,breeze 使用 Angular 自己的 Promise 来实现 Promise,而不是它自己的 breeze.angular.q,后者使用 Q Promise,Q Promise 比 $q 更强大,但也更重。/code> promise Angular 使用哪个。这只是 API 更改。

在 Angular 代码中,您可以使用依赖注入(inject)获取 $q - 例如使用简单的语法:

myApp.controller("MyCtrl",function($q){
//$q is available here
});

或者,如果您想独立使用它,您可以使用服务位置并直接从注入(inject)器获取 $q,但这种情况很少见。 (如果您想要一个示例 - 请告诉我,我只是不想包含通常表明不良做法的代码)。

关于AngularJs console.log "$q is not defined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22379733/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com