纳克模型值不会被更新了的指令 [英] ng-model value is not updated out of the directive

查看:136
本文介绍了纳克模型值不会被更新了的指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请检查Plunker 这里

Please check Plunker here.

该指令在视图中加载如下

The directive is loaded in a view as below

<logic-tree ng-model="myData"> </logic-tree>

和它加载指令的控制器内,该模型被绑定到如以下的变量。

And within the controller which loads the directive, the model is binded to a variable as below.

$scope.myData= { ... };

$scope.$watch( 'myData', function(newValue, oldValue){
  console.log("This is never called");
});

的UpdateModel 被称为 myData的不会被更新。

When updateModel is called, myData is not updated.

请任何人都知道问题出在哪里。

Please anyone knows where the problem is.

推荐答案

您的UpdateModel功能应该有$也呈现:

Your updateModel function should have $render also:

 updateModel = function() {
        setTimeout(function () {
          $scope.$apply(function () {
            ngModelCtrl.$setViewValue($scope.source);
            ngModelCtrl.$render();
          });
        }, 0);
      };

这篇关于纳克模型值不会被更新了的指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆