我有一个聊天指令,用于在页面上放置聊天室。
mod.directive('chat', function () {
return {
templateUrl: '/chat',
replace: true,
scope: {
chatID:'@chat',
},
controller: function ($scope, $element, $timeout) {
var id = $scope.chatID
...
},
link: function ...
}
})
HTML 看起来像这样:
<div class="chat" chat="{{currentChatID}}" ui-view="currentChat"></div>
<div class="content" ui-view="mainContent"></div>
这是在一个名为“标准”的文件中
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
}
}
}
}
})
})
我正在使用 angularjs-ui-router 创建父视图,其中聊天指令在该视图内提供聊天。这在第一页加载时工作正常,聊天加载。但是当我更改页面/聊天室时,我使用另一个控制器来运行setCurrentChatID()
. 这改变了currentChatID
DOM 中的聊天元素,我还看到聊天元素的属性更改为 angularjs-batarang 中的新 ID,但聊天指令的控制器不运行。当 chatID 发生变化时,如何让它正常工作/激活聊天的控制器?
谢谢。