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:
- set initial state of scope object.
- add behavior scope object. (to include creating
$watch
, etc.)
the $digest
loop processes only:
- the
$evalasync
queue - the
$watch
list
Comments
Post a Comment