簡體   English   中英

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

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM