简体   繁体   English

我的控制器未更新我的指令-Angular

[英]My controller is not updating my directive - Angular

I have a directive that shows a detail screen when a row is clicked. 我有一条指令,当单击一行时显示详细信息屏幕。 I am trying to get the encounter to update. 我正在尝试使相遇更新。 Here is the directive: 这是指令:

angular.module('app').directive('chatContainer', function() {
  return {
    scope: {
      encounter: '=',
      count: '='
    },
    templateUrl: 'views/chat.container.html',
    link: function(scope, elem) {
  };
});

Here is the template to the directive: 这是指令的模板:

<div class="span4 chat-container">
 <h5 class="chat-header">
  <span class="container">{{encounter.patient.firstName }} {{encounter.patient.lastName}}</span>
  </h5>
</div>

Here is where the directive is declared in the html: 这是在html中声明指令的位置:

<div chat-container encounter="selectedEncounter" count="count"></div>

And here is the controller that is called when the row is clicked. 这是单击该行时调用的控制器。

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;
});

I get into the function getSelectedRow() and it changes the selectedEncounter to the correct encounter. 我进入函数getSelectedRow() ,它会将selectedEncounter更改为正确的相遇。 The binding does not bring the selection across to my chatContainer . 绑定不会将选择带到我的chatContainer I thought when I declared the encounter in the directive scope and gave it = as the scope type, it bound it, but I am missing something??? 我以为,当我在指令范围中声明encounter的情况并将其=作为范围类型时,它就将其绑定了,但是我却缺少了一些东西?

您需要$apply()进行更改,但是用于操作值的逻辑应该在chatContainer指令内,而不是在控制器内。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM