保留中の$リソース要求を監視し続けるTypescriptでディレクティブを作成しようとしています。ロードの進捗状況を示すためにindex.html内のdivで使用される属性として1つのディレクティブのみを使用します。以下は私のコードのディレクティブです。 Index.htmlとで指示文をタイプスクリプトで作成し、ロード進捗状況を表示します。
module app.common.directives {
interface IProgressbarScope extends ng.IScope {
value: number;
isLoading: any;
showEl: any;
}
class Progressbar implements ng.IDirective {
static $inject = ['$http'];
static instance(): ng.IDirective {
return new Progressbar;
}
//transclude = true;
restrict = 'A';
replace = true;
link = function (scope: IProgressbarScope, elements: ng.IAugmentedJQuery, attrs: ng.IAttributes, $http: ng.IHttpService) {
debugger;
scope.isLoading = function() {
return $http.pendingRequests.length > 0;
};
scope.$watch(scope.isLoading, function (v) {
debugger
if (v) {
elements.addClass("hidediv")
} else {
elements.removeClass("hidediv");
}
});
}
}
angular.module('app')
.directive('progressbar', Progressbar.instance);
}
、それは以下のように使用されます。
<div progressbar id="myProcess" name="myProcess">
// loading image
</div>
しかしディレクティブで、$ HTTPは常に定義されていません。 $ httpを直接使用していないことに注意してください。私はサーバー側のapi要求を行うために$ resourceサービスを使用しています。
ありがとうございました。出来た。クラスを追加するのではなく、elements.show()プロパティを使用できませんか? element.show()を使用すると、「angular.js:13550 TypeError:elements.showは関数ではありません」というエラーが表示されます。 –
@MicrosoftDeveloperは更新された答えをチェックします。プレーンなjavascript関数 –