2017-05-11 61 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(); 
相關問題