【问题标题】:How to use Typescript Q.when()如何使用 Typescript Q.when()
【发布时间】:2016-03-12 03:18:54
【问题描述】:

我有一个返回angular.IPromise<any>的函数

onActivate():IPromise<any>
{
     return Q.when(true);
}

但是当它运行时它说

Q 未定义

虽然,当我查看Q.d.ts 文件时,声明了模块并导出了函数when

如何在 typescript 类中使用 Q 服务?

整个班级是这样的:

/// <reference path="../../typings/q/q.d.ts" />
module app.common.modals
{

export class RenameModalCtrl extends app.common.controllers.ControllerBase
{
    public viewModel: RenameModalModel;
    private $modalInstance: ng.ui.bootstrap.IModalServiceInstance;

    static $inject = ['common', '$translate', '$modalInstance', 'viewModel'];

    constructor(common: any, $translate: angular.translate.ITranslateService, $modalInstance: ng.ui.bootstrap.IModalServiceInstance, viewModel: RenameModalModel)
    {
        super(common, $translate);
        this.viewModel = viewModel;
        this.$modalInstance = $modalInstance;
    }

    onActivate(): ng.IPromise<any>
    {
        return Q.when(true);
    }       
}

angular.module('app').controller('renameModalCtrl', RenameModalCtrl);
}

谢谢

【问题讨论】:

  • 您是否在类定义文件中包含 Q.d.ts 文件?
  • 如果您指的是这一行,那么是的。 ///

标签: angularjs typescript q definitelytyped


【解决方案1】:

您必须在 $inject 中添加 $q 作为您的注射剂之一。然后将其作为 Q 类型添加到您的构造函数中:ng.IQService

编辑:以为你的意思是角度 q。我想你只需要导入模块:

import * as Q from 'q';

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-09
  • 2013-09-07
  • 1970-01-01
  • 1970-01-01
  • 2017-09-15
  • 2021-12-20
相关资源
最近更新 更多