2017-05-11 63 views
0

我正在使用ui-ace指令在角度应用程序中实现ace编辑器。 我有一个按钮,用于动态地将数据添加到ace编辑器。 现在当用户点击按钮时,我使用setValue方法来更新ace编辑器的值,但该值不反映在ngModel中。最好的办法是什么?如何使用setValue更新ui-ace编辑器的值时更新ngModel?

下面是如何设置我所创造的价值...

$scope.addUserInput = function (input) { 
    var currentValue = $scope.aceEditor.getValue(); 

    if(SqlTokenizer.isIdentifier(input.name)){ 
     $scope.aceEditor.setValue(currentValue + ":" + input.name, false); 
    } else{ 
     $scope.aceEditor.setValue(currentValue + ':"'+ input.name +'"', false); 
    } 
}; 

plunkr这里http://plnkr.co/edit/ez0cwr6PWhALpqu3wjZT?p=preview

回答

0

更新plnkr相同:http://plnkr.co/edit/GCnDPQnC7xoC6xqdOeqd

问题是乌尔添加/更新在你的编辑器中的文本不需要这样做。

只需要更新您的范围变量,它会反映在所有的绑定位置。

,而不是这个

//$scope.editor.setValue($scope.editor.getValue() + new Date().getTime()); 

做这个

$scope.text = $scope.text + new Date().getTime(); 
相关问题