0

I am trying to use $ocLazyLoad inside of Angular.js with TypeScript. However I keep getting a Unknown provider error. I am including it in my primary app:

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);
}

The error come from when I try to include it in my 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'
        });
    }

  }
}

The really strange part is that I can include $ocLazyLoadProvider without any problems. This is a very bare-bones setup from Yeoman using gulp, typescript, and ui-router.

4

1 回答 1

1

中有一个错误.config(RouterConfig)

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

于 2015-08-05T00:15:10.490 回答