I'm trying to set up an angular search controller in a project that has existing JavaScript code, using TypeScript.
below is my controller.
/// <reference path="../Models/ISearchSrvc.ts" />
/// <reference path="../Services/searchSrvc.ts"/>
module GLA.Controllers {
export class SearchCtrl {
searchService: Services.SearchSrvc;
searchTerms: string;
pattern: RegExp = /^\s*\w*\s*$/;
static $inject = ["Services.SearchSrvc"];
constuctor(service: Services.SearchSrvc) {
this.searchService = service;
}
searchResults: Models.IResultsContainer;
getSearch = () => {
this.searchResults = this.searchService.search(this.searchTerms);
}
}
angular.module("GLA").controller("GLA.Controllers.SearchCtrl", SearchCtrl);
}
I then import them in the shared _Layout page of the project
<script src="~/Angular/Services/searchSrvc.js"></script>
<script src="~/Angular/Controllers/searchCtrl.js"></script>
Then when use ng-controller to define a div I want to use the controller on, I get Argument 'SearchCtrl' is not a function, got undefined
,
However, if I create a controller in JS, like below:
GLA.controller('testCtrl',['$scope','searchSrvc', function($scopt, searchSrvc) {
$scopt.whatwhat = "whatwhat!!";
}])
This controller can be used on any Div within my project. Any kind of help would be really appreciated!
I have been over this with other developers and as no one bar myself has done much in TypeScript, we've not had any luck, however I am certain other parts have been implemented correctly, its just the issue of a typescript controller in a JavaScript project maybe?
Below is the compiled Controller:
/// <reference path="../Models/ISearchSrvc.ts" />
/// <reference path="../Services/searchSrvc.ts"/>
alert("loaded");
var GLA;
(function(GLA) {
var Controllers;
(function(Controllers) {
var SearchCtrl = (function() {
function SearchCtrl() {
var _this = this;
this.pattern = /^\s*\w*\s*$/;
this.getSearch = function() {
_this.searchResults = _this.searchService.search(_this.searchTerms);
};
}
SearchCtrl.prototype.constuctor = function(service) {
this.searchService = service;
};
SearchCtrl.$inject = ["Services.SearchSrvc"];
return SearchCtrl;
}());
Controllers.SearchCtrl = SearchCtrl;
angular.module("GLA").controller("GLA.Controllers.SearchCtrl", SearchCtrl);
})(Controllers = GLA.Controllers || (GLA.Controllers = {}));
})(GLA || (GLA = {}));
//# sourceMappingURL=searchCtrl.js.map
constuctor(service: Services.SearchSrvc)