Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actors do not work inside ng-view / ng-include #7

Open
csvan opened this issue Aug 24, 2014 · 5 comments
Open

Actors do not work inside ng-view / ng-include #7

csvan opened this issue Aug 24, 2014 · 5 comments

Comments

@csvan
Copy link

csvan commented Aug 24, 2014

Discussion on Lift forum:
https://groups.google.com/forum/#!topic/liftweb/fFgs_-VAx4E

Project demonstrating this issue:
https://github.com/csvan/actor-view-test

Consider the following basic AngularActor:

    case object Ping

    class PingActor extends AngularActor {
      self =>

      def schedule: Unit = Schedule(() => {
        self ! Ping
        schedule
      }, 1000)

      schedule

      override def lowPriority = {
        case Ping =>
          println("Pinging the client!")
          scope.broadcast("broadcast-message", "Broadcast ping received")
          scope.emit("emit-message", "Emitted ping received")
      }
    }

To respond to it, we add the following logic to a controller:

angular.module('testapp.controllers', [])
    .controller('TestController',
    [ '$scope', '$rootScope',
        function ($scope, $rootScope) {

            $scope.$on('broadcast-message', function (e, msg) {
                $scope.broadcastMessage = msg;
                console.log(msg);
            });

            $rootScope.$on('emit-message', function (e, msg) {
                $scope.emitMessage = msg;
                console.log(msg);
            });
        }]);

and finally connect them;

<div ng-controller="TestController">
    <div data-lift="comet?type=PingActor"></div>
</div>

The above works fine, on the condition that the controller is placed in the index.html of the webapp.

If we instead try to place the controller in a view or partial to be included by ng-view or ng-include (respectively) and navigate to the URL causing Angular to load that view/partial, it stops working on the client side. The server still emits pings, but the client no longer logs receives them.

Analysing the network traffic, it is apparent that the client does at least register the incoming messages.

An analysis of the DOM suggests that no Comet bindings at all are generated for the dynamically loaded inner scope: http://hastebin.com/ucodetanaw.xml

@csvan csvan changed the title Actors do not work inside markup generated by ng-view / ng-include Actors do not work inside ng-view / ng-include Aug 24, 2014
@joescii
Copy link
Owner

joescii commented Aug 24, 2014

Hey Christopher! Thanks for the thorough details. I hope you are still enjoying good mileage out of lift-ng despite this issue. Do you have time to set up a minimal sample project demonstrating the issue? That will be a tremendous help. The Lift guidelines for posting example code describes a good approach. I'll have a look when I get a chance in the next couple of days.

@csvan
Copy link
Author

csvan commented Aug 24, 2014

Hi Joe, I have put a brief project together which shows the issue. Please let me know if I can help with anything else related to this.

https://github.com/csvan/actor-view-test

@csvan
Copy link
Author

csvan commented Aug 24, 2014

The following is very interesting. Though they are structurally identical, notice how different the generated code for the outer and inner Comet snippets are. It appears that no Comet binding at all is generated for the inner scope.

http://hastebin.com/ucodetanaw.xml

@tek
Copy link

tek commented Jul 2, 2015

any progress on this? using model bindings in views seems to be the most useful feature of lift-ng for my purposes, I would really like to see that. As far as I can tell, I have to bind all possible models at top scope or else I can't use ngRoute.

@joescii
Copy link
Owner

joescii commented Jul 3, 2015

Sorry @tek, but there is no progress to report. I haven't dug into this in a while, but I think it will require Lift 3.0. Starting then we support adding comet actors after page load. Unless there is something else creative we can do, we will need that feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants