Actors do not work inside ng-view / ng-include
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
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.
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
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
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.
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.