I have search on a lot of websites about adding service into controller in typescript. I have alose tried some example s from dfiffert websites and form stack overflow as well but I am still struggling. Will you please have a look on my code that what is the problem inside.
module Application.Stores {
export class StoreApplication {
private sPresets: IStorePresets;
constructor(presets: IStorePresets) {
this.sPresets = presets;
}
init() {
var newStoresApp = angular.module('NewStoresApp', []);
this.dependency(newStoresApp);
newStoresApp.service('StoreCollectionService', ['$http', '$q', 'sPresets', ($http, $q, sPresets) => new Application.Stores.Services.StoreCollectionService($http, $q, sPresets)]);
// Working but without service
//newStoresApp.controller("CollectionCtrl", ['$scope', ($scope) => new Application.Stores.CollectionCtrl($scope)]);
// Not working
//newStoresApp.controller('CollectionCtrl', ['$scope', 'StoreCollectionService', Application.Stores.CollectionCtrl]);
//Not Working
//newStoresApp.controller("CollectionCtrl", ['$scope', 'StoreCollectionService', ($scope, StoreCollectionService) => new Application.Stores.CollectionCtrl($scope, StoreCollectionService)]);
newStoresApp.controller("CollectionCtrl", []); // How can I do it here?
}
private dependency(app: ng.IModule) {
app.factory("presets", () => {
return this.sPresets;
});
}
}
}
How can I add service into controller in this scanrio?
I have following order of included js files:
Html.RequiresJs("https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js");
Html.RequiresJs("~/Areas/Warehouse/Scripts/Stores/StoreCollectionService.js");
Html.RequiresJs("~/Areas/Warehouse/Scripts/Stores/StoreCollectionsCtrl.js");
Html.RequiresJs("~/Areas/Warehouse/Scripts/Stores/StoresApp.js");
And Code inside controller is as following:
module Application.Stores {
import Services = Application.Stores.StoreCollectionService;
export class CollectionCtrl {
private $scope: any;
private storeCollectionService: StoreCollectionService;
constructor($scope: ng.IScope, storeCollectionService: StoreCollectionService) {
this.$scope = $scope;
this.init();
}
init(): void {
}
private GetAll() {
console.log("Got it all works.");
}
}
}
I have I alos tried this example $inject['service']. For example you can view these helping links to support me in the question.