是否可以将(匿名)从.js
文件中的提供者注入到使用打字稿编写的角度模块中?我正在尝试编译在模块定义中失败的打字稿。
故事
我有一个基本的模块,使用打字稿符号中的角度编写。我正在尝试将adalAuthenticationService
provider 的定义添加到来自adal-angular.js
. 因为提供者不是.d.ts
格式我不能用它作为参考。将提供程序转换.d.ts
为现在是不可能的。所以我留下了匿名注入选项(如果有这样的选项)。
控制器定义
module Temp.NewModule {
interface IMainCtl {
init(): void;
b1(): void;
b2(): void;
}
class MainCtl implements IMainCtl {
hello: string;
txtb1: string;
txtb2: string;
// not sure what effect {private adalService: any} has as it doesn't seem to provide anonymity
constructor(private $scope, private $log: ng.ILogService, private Api: IApi, private adalService: any) {
var vm = this;
this.init();
// not sure if this actually does anything
var adalService = adalAuthenticationService;
}
public init() {
this.Api.getDataRx().subscribe((result) => {
this.hello = result.data.Name;
});
}
public helloWorld() {
this.$log.info('I accept your greeting');
}
public b1() {
this.txtb1 = 'Now Button 1 works';
}
public b2() {
// i am trying to call login function of adalService provider
adalService.login();
}
}
// i am trying to inject adalService provider here
app.controller('MainCtl', ['$scope','$log','Api', MainCtl, adalService]);
}
应用定义
module Temp {
export module NewModule {
export var serviceRoot: string = NewModule.serviceRoot || "";
export var templatePath: string;
export var servicesFramework: any;
//Initalizes angular app
$("html").attr("ng-app", "NewModule");
export var app: ng.IModule = angular.module('NewModule', ['rx', 'ngRoute', 'AdalAngular'])
.config(['$routeProvider', '$httpProvider', 'adalAuthenticationServiceProvider', function($routeProvider, $httpProvider, adalProvider) {
adalProvider
.init ({
tenant: 'tenant.onmicrosoft.com',
clientId: 'client_id',
extraQueryParameter: 'nux=1',
//cacheLocation: 'localStorage', // enable this for IE, as sessionStorage does not work for localhost.
},
$httpProvider
);
}]);
}
}
基本上,我试图绕过编译阶段,adalAuthenticationService
将注入作为依赖项,因为adal-angular.js
包含在内。所以理论上它应该在页面呈现后被拾取。