我有一个我想要调用的指令。它的spinner在promise上工作...所以当promise挂起来调用spinner但是问题是我的指令从未被调用过。任何建议为什么会发生这种情况?
'use strict';
angular.module("mainModule").directive('modulSpinner', ['$timeout', '$rootScope', '$compile', function ($timeout, $rootScope, $compile) {
var getTemplate = function (promise) {
return "<div cg-busy=\"{promise:" + promise + ", message:'', templateUrl:busyModulTemplateURL, minDuration:500}\" > </div>";
}
var linker = function (scope, element, attrs) {
if (angular.isDefined(attrs.promise)) {
var parent = angular.element(document.getElementById('modulSpinner'));
parent.html(getTemplate(attrs.promise));
$compile(parent.contents())(scope);
parent.show();
}
}
return {
restrict: 'E',
link: linker
};
}]);
在HTML中我有这个:
<div class="search-form" ng-controller="autoCompleteController">
<input type="search" ng-model="searchText" ng-model-options="{ debounce: 1000 }" placeholder="@Translator.Translate(" SEARCH_OFFER ")" ng-keydown="checkKeyDown($event);SearchOnEnter($event)" ng-change="search()" ng-enter="Search(searchText)">
<ul class="suggestions-list" ng-if="isExpanded">
<li ng-repeat="suggestion in searchItems track by $index" ng-class="{active : selectedIndex === $index}" ng-click="assignValueAndHide($index)">{{suggestion}}</li>
</ul>
<button type="button" class="primary-button search-button" ng-click="Search(searchText)"></button>
<div modul-spinner promise="autoCompletePromise"></div>
</div>