У меня есть приложение Машинопись Угловая Dependency Injection Отказ
/// <reference path="../Scripts/angular.d.ts" />
/// <reference path="testCtrl.ts" />
/// <reference path="testSvc.ts" />
angular.module('testApp', []);
angular.module('testApp').constant('url','http://whatever');
angular.module('testApp').factory(
'testSvc', ['$http', 'url', testApp.testSvc]);
angular.module('testApp').controller(
'testCtrl', ['testSvc', testApp.testCtrl]);
и контроллер
/// <reference path="../Scripts/angular.d.ts" />
/// <reference path="testSvc.ts" />
module testApp{
export class testCtrl {
public someText:string;
public httpData:any;
public urlName:string;
private data:IData;
static $inject = ['testSvc'];
constructor(testSvc) {
this.someText = 'I am in scope'
this.data = testSvc.getData();
this.httpData = {
putFunc: this.data.putFunc,
expectPUTFunc: this.data.expectPUTFunc
}
this.urlName = this.data.urlName;
}
}}
и услуги
/// <reference path="../Scripts/angular.d.ts" />
/// <reference path="testCtrl.ts" />
interface IData{
urlName:string;
putFunc:string;
expectPUTFunc:string;
}
module testApp{
export class testSvc {
public data:IData;
static $inject = ['$http', 'url'];
constructor(private $http, url) {
this.data = {
urlName:url,
putFunc: typeof $http.put,
expectPUTFunc: typeof $http.expectPUT
}
}
getData(){
return this.data;
}
}}
и эти объявления сценариев в моем HTML
<script type="text/javascript" src="../Scripts/angular.js"></script>
<script src="testSvc.js"></script>
<script src="testCtrl.js"></script>
<script src="testApp.js"></script>
Когда я запускаю это приложение не контроллер никогда не получает свою зависимость от testSvc.getData(), потому что testSvc не определено. Где я иду не так?
Почему вы накладываете свои собственные модули поверх Углового? Какую пользу вы получите от этого дополнительного уровня сложности, дополнительного глобального состояния и семантического дублирования ?. – yangmillstheory