我需要显示ng-model的值,但不会更新

时间:2015-10-26 16:07:48

标签: angularjs

<div class="row ">
        <div class="cell size-p40 " align="right" style="border-width:1px;border-style:solid;border-left-width:0px;border-top-width:0px;padding-right:3px;" >
          <h5>Rendimento Social de Inserção</h5>
        </div>
        <div class="cell size-p10 " style="align:right;border-width:1px;border-style:solid;border-left-width:0px;border-top-width:0px;" >
          <div class="input-control text full-size" style="margin:0px!important;">

            <span class="prepend-icon">€</span>
            <input type="number" align="right" style="direction:RTL;" ng-model="RendimentoSocialInsercao" />
          </div>
        </div>

  </div>
<div class="row ">
      <div class="cell size-p40 " align="right" style="padding-right:3px;border:0px;border-right-width:1px;border-style:solid;" >
        <h5>Total</h5>
      </div>
      <div class="cell size-p10 " style="align:right;border-width:1px;border-style:solid;border-top-width:0px;border-left-width:0px;" >
        {{totalReceitas}}
      </div>

  </div>

我的控制器是 controller.js

    (function() {

  var app = angular.module("caiApp");

  var cDiaController = function($scope,$log) {

    $scope.totalReceitas=$scope.RendimentoSocialInsercao;

 };

  app.controller("cDiaController",['$scope','$log',cDiaController]);

}());

我试图在{{totalReceitas}}中显示我在ng-model =“RendimentoSocialInsercao”中输入的相同值,但它没有更新,我做错了什么?

PS:这是在表单

1 个答案:

答案 0 :(得分:1)

不确定为什么要这样做,但这就是你所缺少的。

(function() {

  var app = angular.module("caiApp");

  var cDiaController = function($scope,$log) {
    $scope.$watch("RendimentoSocialInsercao", function(newVal, oldVal) {
      $scope.totalReceitas=newVal;
    });    
 };

  app.controller("cDiaController",['$scope','$log',cDiaController]);

}());