-
Notifications
You must be signed in to change notification settings - Fork 20
Description
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