2017-03-06 233 views
1

上聚焦場,我採用了棱角分明1.6.2個人項目學習的框架,我無法想出一個辦法來解決這個問題:綁定變量的角度

我有一個變量經常更新(如每秒一次或更少),並且在視圖中有兩個輸入文本字段。我希望變量只在聚焦時更新輸入(和另一個變量)。

爲了更好的用戶體驗,我現在更新了一些視圖,所以現在每個文本輸入都有一個放大按鈕(因爲有時用戶可能希望更新該值,但他需要點擊外部場)。

控制器內部:

$interval(function() { 
    // This gets the updated value from an external source/code. 
    $scope.updatingValue = updatingValueFunc(); 
}, 1000); 

$scope.fields = [ 
    { first: 12323, second: 1430,} 
]; 

HTML:

<div class="field-wrap"> 
    <input type="radio" name="current-bind" value="answer.end"> 
    <input type="number" ng-model="answer.second"> 
</div> 
<div class="field-wrap"> 
    <input type="radio" name="current-bind" value="answer.start"> 
    <input type="number" ng-model="fields.first"> 
</div> 

回答

1

角有你可以用它來調用您的更新功能的NG-重點掛鉤。

<input type="radio" name="current-bind" value="answer.end" ng-focus="updateValue()"/> 

,並在你的JS,你可以創建一個函數來匹配它

$scope.updateValue = function(){ 
    $scope.updatingValue = updatingValueFunc(); 
} 

你也可以使用,如果你想要的功能上,而不是點擊的焦點運行NG點擊。

+0

謝謝,它的工作,我不知道我怎麼沒有想到的:) –