[英]My controller is not updating my directive - Angular
我有一条指令,当单击一行时显示详细信息屏幕。 我正在尝试使相遇更新。 这是指令:
angular.module('app').directive('chatContainer', function() {
return {
scope: {
encounter: '=',
count: '='
},
templateUrl: 'views/chat.container.html',
link: function(scope, elem) {
};
});
这是指令的模板:
<div class="span4 chat-container">
<h5 class="chat-header">
<span class="container">{{encounter.patient.firstName }} {{encounter.patient.lastName}}</span>
</h5>
</div>
这是在html中声明指令的位置:
<div chat-container encounter="selectedEncounter" count="count"></div>
这是单击该行时调用的控制器。
angular.module('app').controller('EncounterCtrl', function ($scope, singleEncounter) {
$scope.count = 500;
$scope.selectedIndex = -1;
$scope.selectedEncounter = -1;
$scope.getSelectedRow = function($index) {
$scope.selectedIndex = $index;
$scope.selectedEncounter = $scope.encounters[$scope.selectedIndex];
};
$scope.encounter = singleEncounter.selectedEncounter;
});
我进入函数getSelectedRow()
,它会将selectedEncounter
更改为正确的相遇。 绑定不会将选择带到我的chatContainer
。 我以为,当我在指令范围中声明encounter
的情况并将其=
作为范围类型时,它就将其绑定了,但是我却缺少了一些东西?
您需要$apply()
进行更改,但是用于操作值的逻辑应该在chatContainer指令内,而不是在控制器内。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.