2017-10-13 23 views
0

我有一個函數,其中我改變按鈕的文本基於一些值傳遞動態值使用角1個插值

$scope.text = 'Wait'; 

if(Number($scope.x) == Number($scope.y)) 
    $scope.text = 'Go' 
else if(Number($scope.x) < Number($scope.y) 
    $scope.text = 'Wait' 

我然後使用text在HTML按鈕標籤上的功能參數

<button type="submit" ng-click="proceed()">{{text}}</button> 

按鈕上的文字proceed功能正在發生。如果文本是等待,我想停止呼叫proceed函數。爲此,我嘗試了這樣的事情。

$scope.check = function(val) { 
    if(val == 'Go') { 
     $scope.proceed(); 
    } 
} 

我用它在HTML類似

<button type="submit" ng-click="check({{text}})">{{text}}</button> 

但我得到一個錯誤,指出

Error: [$parse:syntax] 

我想如果有這樣做的任何其他更好的辦法。任何幫助都感激不盡。

回答

0

不要通過文字這樣。

將其更改爲:

<button type="submit" ng-click="check(text)">{{text}}</button> 

這將解決您的錯誤。

0

您不需要在該點插入文本,您可以將它傳遞給函數。 即:

<button type="submit" ng-click="check(text)">{{text}}</button>