promise-tracker の使用時に問題があります。
私が欲しいのは、会話を追跡することです。私のコードの一部は次のとおりです。
js:
angular.module('myModule', ['ajoslin.promise-tracker'])
.factory('Conversation', function (promiseTracker) {
return {
addMessage: function (opts) {
/* Post data to server */
var promise = POSTING DATA;
promiseTracker('message').addPromise(promise);
},
removeMessage: function (opts) {
/* Delete data */
}
}
})
.directive('newMessage', function (Conversation) {
return {
scope: true,
restrict: 'EA',
link: function (scope) {
scope.addMessage = function () {
Conversation.addMessage( { /* Some opts */ } )
}
}
}
})
.directive('Tracker', function (promiseTracker) {
var opts = { /* Spinner opts */ }
return {
scope: true,
replace: true,
restrict: 'EA',
templateUrl: 'tracker.html',
link: function (scope, element, attrs) {
/* new spinner */
scope.tracker = promiseTracker(attrs.tracker);
/* And some thing */
}
}
})
new-message.html:
<form name="myForm" new-message>
<input type="text" name="content" />
<i tracker="message" ></i>
</form>
tracker.html:
<div>
<div>
<i ng-show="tracker.active()" ng-show="!isHidden"></i>
</div>
<input type="submit" value="submit" ng-click="addMessage()" ng-disabled="tracker.active()">
</div>
これらのコードを使用すると、ページにフォームが 1 つしかない場合にうまく機能します。
しかし、テンプレートにさらにフォームを追加すると、いくつかの問題が発生します。
プロミスを追跡するとき、すべてのスピナーが表示されます!
そして、これは私が欲しいものです:
私のスコープに何か問題があると思います。しかし、私はそれを修正する方法がわかりません。
誰でも私を助けることができますか?どうも!