AngularJs ng-include和socket.io

我是新来的,我不是英文的,所以如果我犯了一些错误,请原谅我。

我的问题是以下一个:我尝试使用angularjs和socket.io(与服务器端nodejs)

所以我有客户端:

<html ng-app="my_app"> <head> ... </head> <body> ... <div id='main_conteneur' ng-controller="CtrlTemplate"> <div ng-include="template.url"></div> </div> </body> </html> 

在lib js上:

 var my_app = angular.module('Quizz', []); my_app.controller('CtrlTemplate', ['$scope', function ($scope) { $scope.template = { name: 'template1.html' , url: 'template/template1.html' }; socket.on('charger_template', function (data) { $scope.template = {name : 'template2.html' , url : 'template/template2.html'}; }); }]); 

并在服务器端的sockets,这样做:

io.sockets.emit('charger_template', data_to_send);

一切工作正常(socket.io正在沟通,angularjs加载我的第一个模板)除了template2.html。 我确实收到服务器的信息,我进入了

socket.on('charger_template', function (data) {});

但模板不会改变。

如果我做一个console.log($范围),我可以看到范围,我可以看到“对象”模板包含“template2.html”

我也尝试了像下面这样的模板,并用数组来改变模板,但是它也不起作用(并且我保留了第一个解决scheme)

 $scope.templates = [ { name: 'template1.html' , url: 'template/template1.html' }, { name: 'template1.html' , url: 'template/template1.html' } ]; $scope.template = $scope.templates[0]; 

我在这里做错了什么?

其实我的模板是正确的设置和我的path了。 我只是忘记使用:

$scope.$apply();