angularjs Directive not reacting to attribute change -


i have chat directive use place chatroom in on page.

mod.directive('chat', function () {   return {     templateurl: '/chat',     replace: true,     scope: {        chatid:'@chat',     },     controller: function ($scope, $element, $timeout) {       var id = $scope.chatid       ...     },     link: function ...   } }) 

html looks this:

<div class="chat" chat="{{currentchatid}}" ui-view="currentchat"></div> <div class="content" ui-view="maincontent"></div> 

this in file called "standard"

mod.config(function($stateprovider) {   $stateprovider.state('standard', {     views: {       'main': {         templateurl: '/tmpl/standard',         controller: function($scope, $timeout) {           $scope.currentchatid = ''           $scope.setcurrentchatid = function(newid) {             $scope.currentchatid = newid           }         }       }     }   }) }) 

i'm using angularjs-ui-router create parent view chat directive providing chat inside view. works fine on first page load, chat loads up. when change page/chat room, use controller run setcurrentchatid(). changes currentchatid chat element in dom, see chat element's properties change new id in angularjs-batarang chat directive's controllers not run. how work / activate chat's controllers when chatid changes.

thanks.

it's hard without seeing rest of chat controller's code, may need $watch inside chat controller like:

$scope.$watch('chatid', function(newvalue, oldvalue) {     // run code here whenever chatid changes }); 

edit: more $digest loop , angular's runtime operations, see angularjs guide. (check runtime section)

for more controllers, see angularjs: understanding controllers guide. here key points relevant question:

controllers should used to:

  1. set initial state of scope object.
  2. add behavior scope object. (to include creating $watch, etc.)

the $digest loop processes only:

  1. the $evalasync queue
  2. the $watch list

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -