Angularjs在onload之后过滤覆盖

时间:2015-06-18 09:37:57

标签: angularjs angular-filters

我使用angularjs语法

在我的页面上使用defualt货币过滤器
{{ '200' | currency:"USD$" }}

在我的页面加载后,我想通过点击操作覆盖货币代码。 我该怎么做?

在页面加载

$200

javascript调用后

€200

2 个答案:

答案 0 :(得分:0)

不要在绑定中使用过滤器,而是在控制器中使用:

myModule.controller("myCtrl", ["$scope", "currencyFilter", function($scope, currencyFilter) {
    $scope.myValue = 200;
    $scope.myCurrency = currencyFilter($scope.myValue, "USD$");
    $scope.updateToEuro = fucntion() {
        $scope.myCurrency = currencyFilter($scope.myValue, "EURO€");
    }
}

然后你的绑定成为:

<span ng-click="updateToEuro()">{{ myCurrency }}</span>

答案 1 :(得分:0)

你可以这样做

myModule.controller("myCtrl", ["$scope", function($scope) {

    $scope.Value = 200;

    $scope.currencyType = "$";

    $scope.changeCurrencyType = function(){
     $scope.currencyType = "€";
    }

}

和像这样的HTML代码

<button type="button" ng-click="changeCurrencyType()">Change Language</button>

<div>{{Value}}{{currencyType}}</div>

希望这适合你。

相关问题