AngularJs console.log“未定义$q" [英] AngularJs console.log "$q is not defined"

查看:29
本文介绍了AngularJs console.log“未定义$q"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在控制台中收到此错误$q is not defined.当我进行一些研究时,我发现诸如 .q 库已被弃用 之类的东西来自http://www.breezejs.com/documentation/breeze-labs/breezeangularqjs

I am getting this error in the console $q is not defined. When I did some research I found some thing like .q library has been deprecated from http://www.breezejs.com/documentation/breeze-labs/breezeangularqjs

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

If this is so, then the whole concept of promises is also deprecated,

推荐答案

Promise 没有被弃用.事实上,它们最近获得了相当大的动力,并被包含在下一个版本的 JavaScript 中.

Promises are not deprecated. In fact they're gaining quite a lot of momentum lately and are included in the next version of JavaScript.

让我们看看他们怎么说:

Let's look at what they say:

这个breed.angular.q 库已被弃用.它被 Breeze Angular Service 取代,后者更干净地为 Angular 开发配置了微风.

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

Breeze Angular 服务告诉 Breeze 将 Angular 的 $q 用于 promise,并使用 Angular 的 $http 进行 ajax 调用.

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

他们说的是,breeze 使用 Angular 自己的 promises 作为 promises,而不是它自己的 breeze.angular.q 使用 Q promises,后者比 $q 承诺 Angular 使用的.这只是 API 更改.

What they say is that breeze uses Angular's own promises for promises rather than its own breeze.angular.q which uses Q promises which are more able but also much heavier than $q promises which Angular uses. This is simply an API change.

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

Inside Angular code, you can obtain $q using dependency injection - for example with the simple syntax:

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

或者,如果您想独立使用它,您可以使用服务位置并直接从注入器获取 $q,但这种情况很少见.(如果你想要一个例子 - 让我知道,我宁愿不包含通常表明错误做法的代码).

Alternatively, if you want to use it independently you can use service location and obtain $q directly from an injector, but that's rarely the case. (If you want an example - let me know, I'd just rather not include code that's usually indicative of bad practice).

这篇关于AngularJs console.log“未定义$q"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆