【问题标题】:Unknown provider $ocLazyLoad when using with TypeScript与 TypeScript 一起使用时的未知提供程序 $ocLazyLoad
【发布时间】:2015-10-27 13:45:12
【问题描述】:

我正在尝试在带有 TypeScript 的 Angular.js 中使用 $ocLazyLoad。但是我不断收到Unknown provider error。我将它包含在我的主应用程序中:

index.module.ts

/// <reference path="../../.tmp/typings/tsd.d.ts" />
/// <reference path="index.route.ts" />
/// <reference path="index.config.ts" />
/// <reference path="index.run.ts" />

module myApp {
  'use strict';

  angular.module('myApp', [
    'ui.router',
    'oc.lazyLoad'])
    .config(RouterConfig)
    .config(Config)
    .run(RunBlock);
}

当我尝试将它包含在我的RouterConfig 中时,错误来自:

index.route.ts

module myApp {
  'use strict';

  export class RouterConfig {

    static $inject = ['$stateProvider', '$urlRouterProvider', '$ocLazyLoad'];

    constructor($stateProvider: ng.ui.IStateProvider, $urlRouterProvider: ng.ui.IUrlRouterProvider, $ocLazyLoad: oc.ILazyLoad) {
      $urlRouterProvider.otherwise('/dashboard');

      $stateProvider
        .state('dashboard', {
          url: '/dashboard',
          templateUrl: 'app/modules/core/dashboard/dashboard.html'
        });
    }

  }
}

真正奇怪的是我可以毫无问题地包含$ocLazyLoadProvider。这是来自Yeoman using gulp, typescript, and ui-router 的非常简单的设置。

【问题讨论】:

    标签: angularjs typescript angular-ui-router oclazyload


    【解决方案1】:

    .config(RouterConfig) 中有错误。

    传递给config函数 不是用new 运算符调用的,因此这里不要使用打字稿class

    【讨论】:

    • 你确定吗?当我不包含 $ocLazyLoad 时,RouterConfig 效果很好。另外,这是一个由Yeoman generator 生成的类——我没有创建它。
    • @lightswitch05 是的。只要您认为可以使用this,您就会遇到问题
    猜你喜欢
    • 1970-01-01
    • 2018-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-23
    • 2017-02-28
    • 1970-01-01
    相关资源
    最近更新 更多