AngularJS ngModel doesn't work inside a ui-bootstrap tabset

前端 未结 1 1064
情话喂你
情话喂你 2021-02-20 15:11

The following code illustrates the problem:



  
    AngularJS Plunker         


        
1条回答
  •  日久生厌
    2021-02-20 15:46

    Almost certainly the issue is that you are trying to bind to a primitive (in this case a float). Something like this should fix it.

    $scope.data = {}
    $scope.updateValueInScope = function () {
      $scope.data.valueInScope = $scope.data.value;
      $scope.changes++;
    }
    

    Basically in angular, if you bind to a primitive the value of the variable is passed around, and not the reference to it, which can break 2-way binding. I'm guessing that the tabset directive creates its own scope, so the valueInScope variable defined in the controller loses its binding in the child scope of the tabset because its a primitive. Anyway, don't bind to primitives and it should work.

    Here is a fixed version of plunk

    0 讨论(0)
提交回复
热议问题