Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

@csvan

Description

@csvan

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions