Question: promise-tracker in AngularJS

219 views
Skip to first unread message

ZX Guan

unread,
Jul 13, 2013, 8:44:40 PM7/13/13
to ang...@googlegroups.com
I have problems when using promise-tracker.

What I want is to track a conversation. And part of my code is following:

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>
-----------------------------------------------------------------------------------------

With these code, It works well when there is ONLY ONE form in the page.

BUT when I add more form in the template, it has some problems. 

When tracking a promise, all spinner show!

now result

And this is what I want:


I suppose that there is something wrong in my scope. But I don't know how to fix it.

Can anyone help me?

Thx!
Reply all
Reply to author
Forward
0 new messages