TypeScriptを使用して既存のJavaScriptコードを持つプロジェクトで角度検索コントローラを設定しようとしています。JavaScript Angular ProjectのTypeScript - 引数が 'SearchCtrl'が関数ではないか、または未定義です
以下が私のコントローラです。使用NG-コントローラは、私が上のコントローラを使用したいのdivを定義するとき、私はその後、私はArgument 'SearchCtrl' is not a function, got undefined
を取得し、その後、プロジェクトの共有_layoutページ
<script src="~/Angular/Services/searchSrvc.js"></script>
<script src="~/Angular/Controllers/searchCtrl.js"></script>
でそれらをインポート
/// <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);
}
、
しかし、私は以下のようなJSのコントローラを作成した場合:
GLA.controller('testCtrl',['$scope','searchSrvc', function($scopt, searchSrvc) {
$scopt.whatwhat = "whatwhat!!";
}])
このコントローラはプロジェクト内のどの部門でも使用できます。 どんな種類のヘルプが本当に感謝しています!
私はこれを他の開発者と一緒に過ごしていますし、TypeScriptで多大な努力をしたことがないので、私たちは幸運を祈ることはありませんでしたが、正しく実装されていることは確かです。 JavaScriptプロジェクトのコントローラはおそらく?
angular.module("GLA").controller("GLA.Controllers.SearchCtrl", SearchCtrl);
はそれを変更:以下
は私に悲しみを引き起こしていたラインで、私は最終的にそれを働い/// <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
TypeScriptソースから生成されたJavaScriptを見ましたか? – Bludwarf
コンソールエラーはありますか? –
@MiteshPantコンソールの唯一のエラーは、コントローラがファンクション/未定義ではないことを指すエラーです。 -/ – Baulers