user3530257 user3530257 - 1 year ago 59
AngularJS Question

View(Template) does not update when the controller changes

I have a directive that pushes element to an array, and then shows the elements on the view, the problem is that even though the array gets updated (the log shows the correct values) the view keeps showing the empty array. What am I doing wrong?

Note: I do not need the parent's $scope for anything, all I'm adding/modifying is on the directive's scope.


app.directive('streaming', function(){
return {
restrict: 'EA',
scope: {
live: '&',
data: '&',
controller: function($scope){
//Eventually this reaches $scope.messages.push({..});
templateUrl: '/directives/templates/streaming.html'


<div class="row" >
<canvas id="canvas" width="640px" height="360px"></canvas>
<div ng-show="live" id="chat">
<div ng-repeat="m in messages">
<div ng-if="m.type==0"><!--sistema-->
<div ng-if="m.type==1"><!--Usuario-->

Answer Source

I had to wrap the $scope.messages modifications in a $scope.apply() to get the view to reflect the actual value. I'm not entirely sure why. This solved my problem

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download